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: cast_to.ty.is_unsafe_ptr() #120925

Closed
matthiaskrgr opened this issue Feb 11, 2024 · 1 comment · Fixed by #121039
Closed

ice: cast_to.ty.is_unsafe_ptr() #120925

matthiaskrgr opened this issue Feb 11, 2024 · 1 comment · Fixed by #121039
Assignees
Labels
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) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

auto-reduced (treereduce-rust):

static FOO: fn() = || assert_ne!(42, 43);
static BAR: fn(i32, i32) = |a, b| assert_ne!(a, b);

fn main() {
    FOO();

    let bar: unsafe fn(i32, i32) = BAR;

    let f: fn() = || {};
    f();

    f();

    f();

    let g: fn(i32) = |i| assert_eq!(i, 2);
    g(2);

    g(2);

    g(2);
}

original:

static FOO: fn() = || assert_ne!(42, 43);
static BAR: fn(i32, i32) = |a, b| assert_ne!(a, b);

// use to first make the closure FnOnce() before making it fn()
fn force_once0<R, F: FnOnce() -> R>(f: F) -> F {
    f
}
fn force_once1<T, R, F: FnOnce(T) -> R>(f: F) -> F {
    f
}
fn force_mut0<R, F: FnMut() -> R>(f: F) -> F {
    f
}
fn force_mut1<T, R, F: FnMut(T) -> R>(f: F) -> F {
    f
}

fn main() {
    FOO();
    BAR(44, 45);
    let bar: unsafe fn(i32, i32) = BAR;
    unsafe { bar(46, 47) };
    let boo: &dyn Fn(i32, i32) = &BAR;
    boo(48, 49);

    let f: fn() = || {};
    f();
    let f = force_once0(|| {}) as fn();
    f();
    let f = force_mut0(|| {}) as fn();
    f();

    let g: fn(i32) = |i| assert_eq!(i, 2);
    g(2);
    let g = force_once1(|i| assert_eq!(i, 2)) as fn(i32);
    g(2);
    let g = force_mut1(|i| assert_eq!(i, 2)) as fn(i32);
    g(2);
}

Version information

rustc 1.78.0-nightly (9aa232ecc 2024-02-11)
binary: rustc
commit-hash: 9aa232ecc7bb006a1fad404f437b049482021a3a
commit-date: 2024-02-11
host: x86_64-unknown-linux-gnu
release: 1.78.0-nightly
LLVM version: 17.0.6

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Zmir-opt-level=5

Program output

warning: unused variable: `bar`
 --> /tmp/icemaker_global_tempdir.tkO1egN3Uvx5/rustc_testrunner_tmpdir_reporting.BMSxZ0VHemue/mvce.rs:7:9
  |
7 |     let bar: unsafe fn(i32, i32) = BAR;
  |         ^^^ help: if this is intentional, prefix it with an underscore: `_bar`
  |
  = note: `#[warn(unused_variables)]` on by default

thread 'rustc' panicked at /rustc/9aa232ecc7bb006a1fad404f437b049482021a3a/compiler/rustc_const_eval/src/interpret/cast.rs:203:9:
assertion failed: cast_to.ty.is_unsafe_ptr()
stack backtrace:
   0:     0x7f7c9d986416 - std::backtrace_rs::backtrace::libunwind::trace::haa332446d2816da1
                               at /rustc/9aa232ecc7bb006a1fad404f437b049482021a3a/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1:     0x7f7c9d986416 - std::backtrace_rs::backtrace::trace_unsynchronized::hc79ac4bb87de99b7
                               at /rustc/9aa232ecc7bb006a1fad404f437b049482021a3a/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f7c9d986416 - std::sys_common::backtrace::_print_fmt::h826e31038d6fed55
                               at /rustc/9aa232ecc7bb006a1fad404f437b049482021a3a/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7f7c9d986416 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h7d45101adaea8e2e
                               at /rustc/9aa232ecc7bb006a1fad404f437b049482021a3a/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f7c9d9d8f90 - core::fmt::rt::Argument::fmt::habb091c2e565929c
                               at /rustc/9aa232ecc7bb006a1fad404f437b049482021a3a/library/core/src/fmt/rt.rs:142:9
   5:     0x7f7c9d9d8f90 - core::fmt::write::h430cd915198bfbfa
                               at /rustc/9aa232ecc7bb006a1fad404f437b049482021a3a/library/core/src/fmt/mod.rs:1120:17
   6:     0x7f7c9d979c9f - std::io::Write::write_fmt::h76a4f85596572687
                               at /rustc/9aa232ecc7bb006a1fad404f437b049482021a3a/library/std/src/io/mod.rs:1854:15
   7:     0x7f7c9d9861f4 - std::sys_common::backtrace::_print::h730103227e62d0c1
                               at /rustc/9aa232ecc7bb006a1fad404f437b049482021a3a/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7f7c9d9861f4 - std::sys_common::backtrace::print::h4b37a0052f447bb6
                               at /rustc/9aa232ecc7bb006a1fad404f437b049482021a3a/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7f7c9d988fe7 - std::panicking::default_hook::{{closure}}::h9ce01cf4995c297e
  10:     0x7f7c9d988d49 - std::panicking::default_hook::h82708ac75720d681
                               at /rustc/9aa232ecc7bb006a1fad404f437b049482021a3a/library/std/src/panicking.rs:292:9
  11:     0x7f7c9a74999c - std[2504e1f5e79dbd0a]::panicking::update_hook::<alloc[4e175fcaaf6bf4c3]::boxed::Box<rustc_driver_impl[f5849ce36d1a60d2]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7f7c9d989736 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h9c044ab60f052747
                               at /rustc/9aa232ecc7bb006a1fad404f437b049482021a3a/library/alloc/src/boxed.rs:2030:9
  13:     0x7f7c9d989736 - std::panicking::rust_panic_with_hook::h47b07230e93314a2
                               at /rustc/9aa232ecc7bb006a1fad404f437b049482021a3a/library/std/src/panicking.rs:785:13
  14:     0x7f7c9d989449 - std::panicking::begin_panic_handler::{{closure}}::h6c5fbc890ce207d0
                               at /rustc/9aa232ecc7bb006a1fad404f437b049482021a3a/library/std/src/panicking.rs:651:13
  15:     0x7f7c9d986916 - std::sys_common::backtrace::__rust_end_short_backtrace::hec2f82c01fee32cd
                               at /rustc/9aa232ecc7bb006a1fad404f437b049482021a3a/library/std/src/sys_common/backtrace.rs:171:18
  16:     0x7f7c9d9891d4 - rust_begin_unwind
                               at /rustc/9aa232ecc7bb006a1fad404f437b049482021a3a/library/std/src/panicking.rs:647:5
  17:     0x7f7c9d9d56e5 - core::panicking::panic_fmt::h48a1a0d3500755c9
                               at /rustc/9aa232ecc7bb006a1fad404f437b049482021a3a/library/core/src/panicking.rs:72:14
  18:     0x7f7c9d9d57a3 - core::panicking::panic::h38ca9e7edcd01163
                               at /rustc/9aa232ecc7bb006a1fad404f437b049482021a3a/library/core/src/panicking.rs:144:5
  19:     0x7f7c9c29e56c - <rustc_mir_transform[156c0abd78acfd74]::gvn::VnState>::insert
  20:     0x7f7c9c0601a5 - <rustc_mir_transform[156c0abd78acfd74]::gvn::VnState>::simplify_rvalue
  21:     0x7f7c9999ae61 - <rustc_mir_transform[156c0abd78acfd74]::gvn::GVN as rustc_middle[dddd7df0b25e8df]::mir::MirPass>::run_pass
  22:     0x7f7c9ba10a29 - rustc_mir_transform[156c0abd78acfd74]::pass_manager::run_passes_inner
  23:     0x7f7c9bf2882a - rustc_mir_transform[156c0abd78acfd74]::optimized_mir
  24:     0x7f7c9ba7a535 - rustc_query_impl[6d1f17dd37feccf6]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[6d1f17dd37feccf6]::query_impl::optimized_mir::dynamic_query::{closure#2}::{closure#0}, rustc_middle[dddd7df0b25e8df]::query::erase::Erased<[u8; 8usize]>>
  25:     0x7f7c9ba7abe1 - rustc_query_system[e40b0ad2841d92dc]::query::plumbing::try_execute_query::<rustc_query_impl[6d1f17dd37feccf6]::DynamicConfig<rustc_query_system[e40b0ad2841d92dc]::query::caches::DefIdCache<rustc_middle[dddd7df0b25e8df]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[6d1f17dd37feccf6]::plumbing::QueryCtxt, false>
  26:     0x7f7c9ba7a35e - rustc_query_impl[6d1f17dd37feccf6]::query_impl::optimized_mir::get_query_non_incr::__rust_end_short_backtrace
  27:     0x7f7c98a00be8 - <rustc_middle[dddd7df0b25e8df]::ty::context::TyCtxt>::instance_mir
  28:     0x7f7c995b40f1 - rustc_monomorphize[f093a8358fafe6ae]::collector::collect_items_rec::{closure#0}
  29:     0x7f7c9c8b2416 - rustc_monomorphize[f093a8358fafe6ae]::collector::collect_items_rec
  30:     0x7f7c9c8adaff - rustc_monomorphize[f093a8358fafe6ae]::partitioning::collect_and_partition_mono_items
  31:     0x7f7c9c8ad170 - rustc_query_impl[6d1f17dd37feccf6]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[6d1f17dd37feccf6]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2}::{closure#0}, rustc_middle[dddd7df0b25e8df]::query::erase::Erased<[u8; 24usize]>>
  32:     0x7f7c9c8ad155 - <rustc_query_impl[6d1f17dd37feccf6]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2} as core[ae955e53bd86118a]::ops::function::FnOnce<(rustc_middle[dddd7df0b25e8df]::ty::context::TyCtxt, ())>>::call_once
  33:     0x7f7c9c8ac4c7 - rustc_query_system[e40b0ad2841d92dc]::query::plumbing::try_execute_query::<rustc_query_impl[6d1f17dd37feccf6]::DynamicConfig<rustc_query_system[e40b0ad2841d92dc]::query::caches::SingleCache<rustc_middle[dddd7df0b25e8df]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[6d1f17dd37feccf6]::plumbing::QueryCtxt, false>
  34:     0x7f7c9c8ac1c9 - rustc_query_impl[6d1f17dd37feccf6]::query_impl::collect_and_partition_mono_items::get_query_non_incr::__rust_end_short_backtrace
  35:     0x7f7c9c6f0d95 - rustc_codegen_ssa[1e476fc2cbfb7ad1]::base::codegen_crate::<rustc_codegen_llvm[35c5f462c9ac856d]::LlvmCodegenBackend>
  36:     0x7f7c9c6f0a49 - <rustc_codegen_llvm[35c5f462c9ac856d]::LlvmCodegenBackend as rustc_codegen_ssa[1e476fc2cbfb7ad1]::traits::backend::CodegenBackend>::codegen_crate
  37:     0x7f7c9c97f0f0 - rustc_interface[614167ae26197186]::passes::start_codegen
  38:     0x7f7c9c97e835 - <rustc_interface[614167ae26197186]::queries::Queries>::codegen_and_build_linker
  39:     0x7f7c9c7300c5 - rustc_interface[614167ae26197186]::interface::run_compiler::<core[ae955e53bd86118a]::result::Result<(), rustc_span[5816d1300c2c104a]::ErrorGuaranteed>, rustc_driver_impl[f5849ce36d1a60d2]::run_compiler::{closure#0}>::{closure#0}
  40:     0x7f7c9c96e0d2 - std[2504e1f5e79dbd0a]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[614167ae26197186]::util::run_in_thread_with_globals<rustc_interface[614167ae26197186]::util::run_in_thread_pool_with_globals<rustc_interface[614167ae26197186]::interface::run_compiler<core[ae955e53bd86118a]::result::Result<(), rustc_span[5816d1300c2c104a]::ErrorGuaranteed>, rustc_driver_impl[f5849ce36d1a60d2]::run_compiler::{closure#0}>::{closure#0}, core[ae955e53bd86118a]::result::Result<(), rustc_span[5816d1300c2c104a]::ErrorGuaranteed>>::{closure#0}, core[ae955e53bd86118a]::result::Result<(), rustc_span[5816d1300c2c104a]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[ae955e53bd86118a]::result::Result<(), rustc_span[5816d1300c2c104a]::ErrorGuaranteed>>
  41:     0x7f7c9c96defe - <<std[2504e1f5e79dbd0a]::thread::Builder>::spawn_unchecked_<rustc_interface[614167ae26197186]::util::run_in_thread_with_globals<rustc_interface[614167ae26197186]::util::run_in_thread_pool_with_globals<rustc_interface[614167ae26197186]::interface::run_compiler<core[ae955e53bd86118a]::result::Result<(), rustc_span[5816d1300c2c104a]::ErrorGuaranteed>, rustc_driver_impl[f5849ce36d1a60d2]::run_compiler::{closure#0}>::{closure#0}, core[ae955e53bd86118a]::result::Result<(), rustc_span[5816d1300c2c104a]::ErrorGuaranteed>>::{closure#0}, core[ae955e53bd86118a]::result::Result<(), rustc_span[5816d1300c2c104a]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[ae955e53bd86118a]::result::Result<(), rustc_span[5816d1300c2c104a]::ErrorGuaranteed>>::{closure#1} as core[ae955e53bd86118a]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  42:     0x7f7c9d992925 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h3205da42e967968e
                               at /rustc/9aa232ecc7bb006a1fad404f437b049482021a3a/library/alloc/src/boxed.rs:2016:9
  43:     0x7f7c9d992925 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h3a8d804b35a578bc
                               at /rustc/9aa232ecc7bb006a1fad404f437b049482021a3a/library/alloc/src/boxed.rs:2016:9
  44:     0x7f7c9d992925 - std::sys::pal::unix::thread::Thread::new::thread_start::ha87a0836a03cdbad
                               at /rustc/9aa232ecc7bb006a1fad404f437b049482021a3a/library/std/src/sys/pal/unix/thread.rs:108:17
  45:     0x7f7c978749eb - <unknown>
  46:     0x7f7c978f87cc - <unknown>
  47:                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: rustc 1.78.0-nightly (9aa232ecc 2024-02-11) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z mir-opt-level=5 -Z dump-mir-dir=dir

query stack during panic:
#0 [optimized_mir] optimizing MIR for `main`
#1 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
warning: 1 warning emitted


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

matthiaskrgr commented Feb 11, 2024

cc @cjgillot #120405

@cjgillot cjgillot self-assigned this Feb 11, 2024
@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 12, 2024
@matthiaskrgr matthiaskrgr added the A-mir-opt Area: MIR optimizations label Feb 12, 2024
@bors bors closed this as completed in 93bc340 Feb 14, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Feb 14, 2024
Rollup merge of rust-lang#121039 - cjgillot:gvn-adjust, r=compiler-errors

Correctly compute adjustment casts in GVN

Fixes rust-lang#120925

r? `@oli-obk`
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-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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants