Skip to content

assertion hit in GVN with unsafe binder #137846

Closed
@matthiaskrgr

Description

@matthiaskrgr

also reproducible with just `-Copt-level=3´

auto-reduced (treereduce-rust):

//@compile-flags: -Zmir-enable-passes=+GVN
#![feature(unsafe_binders)]

use std::unsafe_binder::wrap_binder;

fn main() {
    unsafe {
        let x = 1;
        let binder: unsafe<'a> &'a i32 = wrap_binder!(&x);
    }
}

original:

#![feature(unsafe_binders)]
//~| WARN block uses type `Option<UnsafeCell<NonZero<usize>>>`, which is not FFI-safe

use std::unsafe_binder::{wrap_binder, unwrap_binder};

fn main() {
    unsafe {
    let x = 1;
        let binder: unsafe<'a> &'a i32 = wrap_binder!(&x);
        //~^ ERROR unsafe binder casts are not fully implemented
        let rx = *unwrap_binder!(binder);
        //~^ ERROR unsafe binder casts are not fully implemented
    }
}

Version information

rustc 1.87.0-nightly (002da7682 2025-03-01)
binary: rustc
commit-hash: 002da76821d32c8807dc47da16660925d8cc9b62
commit-date: 2025-03-01
host: x86_64-unknown-linux-gnu
release: 1.87.0-nightly
LLVM version: 20.1.0

Possibly related line of code:

};
cfg_checker.visit_body(body);
cfg_checker.check_cleanup_control_flow();
// Also run the TypeChecker.
for (location, msg) in validate_types(tcx, typing_env, body, body) {
cfg_checker.fail(location, msg);
}
if let MirPhase::Runtime(_) = body.phase {
if let ty::InstanceKind::Item(_) = body.source.instance {
if body.has_free_regions() {
cfg_checker.fail(

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Zmir-enable-passes=+GVN

Program output

warning: the feature `unsafe_binders` is incomplete and may not be safe to use and/or cause compiler crashes
 --> /tmp/icemaker_global_tempdir.LGrvNoC79FrB/rustc_testrunner_tmpdir_reporting.Ia8piCAvtVIZ/mvce.rs:1:12
  |
1 | #![feature(unsafe_binders)]
  |            ^^^^^^^^^^^^^^
  |
  = note: see issue #130516 <https://github.com/rust-lang/rust/issues/130516> for more information
  = note: `#[warn(incomplete_features)]` on by default

warning: unused variable: `binder`
 --> /tmp/icemaker_global_tempdir.LGrvNoC79FrB/rustc_testrunner_tmpdir_reporting.Ia8piCAvtVIZ/mvce.rs:8:13
  |
8 |         let binder: unsafe<'a> &'a i32 = wrap_binder!(&x);
  |             ^^^^^^ help: if this is intentional, prefix it with an underscore: `_binder`
  |
  = note: `#[warn(unused_variables)]` on by default


thread 'rustc' panicked at compiler/rustc_mir_transform/src/validate.rs:80:25:
broken MIR in Item(DefId(0:4 ~ mvce[9539]::main)) (after phase change to runtime-optimized) at bb0[2]:
encountered `Assign((_2, copy _3))` with incompatible types:
left-hand side has type: for<'a> &'a i32
right-hand side has type: &i32
stack backtrace:
   0:     0x71462a1bdcd4 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h579a9ebf0bc5a7dc
   1:     0x71462aa1b8ac - core::fmt::write::h03111b4508112a37
   2:     0x71462ba51e11 - std::io::Write::write_fmt::hd0ad153b3561b0fb
   3:     0x71462a1bdb32 - std::sys::backtrace::BacktraceLock::print::h2ca9a9268eae9e1c
   4:     0x71462a1c036e - std::panicking::default_hook::{{closure}}::hb3938e948a7ac1ea
   5:     0x71462a1bff44 - std::panicking::default_hook::h4fc34f6edc5a27a3
   6:     0x714629317427 - std[deb2ef2c18d5a489]::panicking::update_hook::<alloc[32b1718cd29ecd9e]::boxed::Box<rustc_driver_impl[c1af299d1397a699]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x71462a1c0be3 - std::panicking::rust_panic_with_hook::h96a77221e7d10566
   8:     0x71462a1c08da - std::panicking::begin_panic_handler::{{closure}}::hea7a96e208531c31
   9:     0x71462a1be1a9 - std::sys::backtrace::__rust_end_short_backtrace::hcf2a76a002efecaf
  10:     0x71462a1c059d - rust_begin_unwind
  11:     0x714626e5aa30 - core::panicking::panic_fmt::hc39c2889396fd69d
  12:     0x714627f7b4d2 - <rustc_mir_transform[eb8b3660ec683aa2]::validate::CfgChecker>::fail::<alloc[32b1718cd29ecd9e]::string::String>
  13:     0x71462b3dba9d - <rustc_mir_transform[eb8b3660ec683aa2]::validate::Validator as rustc_mir_transform[eb8b3660ec683aa2]::pass_manager::MirPass>::run_pass
  14:     0x71462aa0491c - rustc_mir_transform[eb8b3660ec683aa2]::pass_manager::run_passes_inner
  15:     0x71462b649a7d - rustc_mir_transform[eb8b3660ec683aa2]::optimized_mir
  16:     0x71462b6492b3 - rustc_query_impl[86676211619dbe61]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[86676211619dbe61]::query_impl::optimized_mir::dynamic_query::{closure#2}::{closure#0}, rustc_middle[13f0c7f73c4d7a3a]::query::erase::Erased<[u8; 8usize]>>
  17:     0x71462aacb5b2 - rustc_query_system[551d7db41c0528f3]::query::plumbing::try_execute_query::<rustc_query_impl[86676211619dbe61]::DynamicConfig<rustc_query_system[551d7db41c0528f3]::query::caches::DefIdCache<rustc_middle[13f0c7f73c4d7a3a]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[86676211619dbe61]::plumbing::QueryCtxt, false>
  18:     0x71462aaca920 - rustc_query_impl[86676211619dbe61]::query_impl::optimized_mir::get_query_non_incr::__rust_end_short_backtrace
  19:     0x71462af5a36b - <rustc_middle[13f0c7f73c4d7a3a]::ty::context::TyCtxt>::instance_mir
  20:     0x71462817c667 - rustc_monomorphize[c6a168d86abacc06]::mono_checks::check_mono_item
  21:     0x71462af5d9a0 - rustc_query_impl[86676211619dbe61]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[86676211619dbe61]::query_impl::check_mono_item::dynamic_query::{closure#2}::{closure#0}, rustc_middle[13f0c7f73c4d7a3a]::query::erase::Erased<[u8; 0usize]>>
  22:     0x71462af5d2d1 - rustc_query_system[551d7db41c0528f3]::query::plumbing::try_execute_query::<rustc_query_impl[86676211619dbe61]::DynamicConfig<rustc_query_system[551d7db41c0528f3]::query::caches::DefaultCache<rustc_middle[13f0c7f73c4d7a3a]::ty::instance::Instance, rustc_middle[13f0c7f73c4d7a3a]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[86676211619dbe61]::plumbing::QueryCtxt, false>
  23:     0x71462af5cf8e - rustc_query_impl[86676211619dbe61]::query_impl::check_mono_item::get_query_non_incr::__rust_end_short_backtrace
  24:     0x714628169e01 - rustc_monomorphize[c6a168d86abacc06]::collector::items_of_instance
  25:     0x71462b4ddbb2 - rustc_query_impl[86676211619dbe61]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[86676211619dbe61]::query_impl::items_of_instance::dynamic_query::{closure#2}::{closure#0}, rustc_middle[13f0c7f73c4d7a3a]::query::erase::Erased<[u8; 32usize]>>
  26:     0x71462b4dd3e9 - rustc_query_system[551d7db41c0528f3]::query::plumbing::try_execute_query::<rustc_query_impl[86676211619dbe61]::DynamicConfig<rustc_query_system[551d7db41c0528f3]::query::caches::DefaultCache<(rustc_middle[13f0c7f73c4d7a3a]::ty::instance::Instance, rustc_middle[13f0c7f73c4d7a3a]::mir::mono::CollectionMode), rustc_middle[13f0c7f73c4d7a3a]::query::erase::Erased<[u8; 32usize]>>, false, false, false>, rustc_query_impl[86676211619dbe61]::plumbing::QueryCtxt, false>
  27:     0x71462b4dd02e - rustc_query_impl[86676211619dbe61]::query_impl::items_of_instance::get_query_non_incr::__rust_end_short_backtrace
  28:     0x71462b4df03a - rustc_monomorphize[c6a168d86abacc06]::collector::collect_items_rec::{closure#0}
  29:     0x71462b4dfff5 - rustc_monomorphize[c6a168d86abacc06]::collector::collect_items_rec
  30:     0x71462af50264 - rustc_monomorphize[c6a168d86abacc06]::collector::collect_crate_mono_items
  31:     0x71462bc648e6 - rustc_monomorphize[c6a168d86abacc06]::partitioning::collect_and_partition_mono_items
  32:     0x71462bc64864 - rustc_query_impl[86676211619dbe61]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[86676211619dbe61]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2}::{closure#0}, rustc_middle[13f0c7f73c4d7a3a]::query::erase::Erased<[u8; 40usize]>>
  33:     0x71462bc64849 - <rustc_query_impl[86676211619dbe61]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2} as core[cbb3bcf71ac95dcb]::ops::function::FnOnce<(rustc_middle[13f0c7f73c4d7a3a]::ty::context::TyCtxt, ())>>::call_once
  34:     0x71462bc63f8e - rustc_query_system[551d7db41c0528f3]::query::plumbing::try_execute_query::<rustc_query_impl[86676211619dbe61]::DynamicConfig<rustc_query_system[551d7db41c0528f3]::query::caches::SingleCache<rustc_middle[13f0c7f73c4d7a3a]::query::erase::Erased<[u8; 40usize]>>, false, false, false>, rustc_query_impl[86676211619dbe61]::plumbing::QueryCtxt, false>
  35:     0x71462bc63d1f - rustc_query_impl[86676211619dbe61]::query_impl::collect_and_partition_mono_items::get_query_non_incr::__rust_end_short_backtrace
  36:     0x71462baf9c9e - <rustc_codegen_llvm[f942c5d9fb23fdbb]::LlvmCodegenBackend as rustc_codegen_ssa[200a86b0c65d429e]::traits::backend::CodegenBackend>::codegen_crate
  37:     0x71462bb05c1b - <rustc_interface[e115f2a012085938]::queries::Linker>::codegen_and_build_linker
  38:     0x71462bb3def0 - rustc_interface[e115f2a012085938]::passes::create_and_enter_global_ctxt::<core[cbb3bcf71ac95dcb]::option::Option<rustc_interface[e115f2a012085938]::queries::Linker>, rustc_driver_impl[c1af299d1397a699]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  39:     0x71462bb2e820 - rustc_interface[e115f2a012085938]::interface::run_compiler::<(), rustc_driver_impl[c1af299d1397a699]::run_compiler::{closure#0}>::{closure#1}
  40:     0x71462b97b748 - std[deb2ef2c18d5a489]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[e115f2a012085938]::util::run_in_thread_with_globals<rustc_interface[e115f2a012085938]::util::run_in_thread_pool_with_globals<rustc_interface[e115f2a012085938]::interface::run_compiler<(), rustc_driver_impl[c1af299d1397a699]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  41:     0x71462b97c034 - <<std[deb2ef2c18d5a489]::thread::Builder>::spawn_unchecked_<rustc_interface[e115f2a012085938]::util::run_in_thread_with_globals<rustc_interface[e115f2a012085938]::util::run_in_thread_pool_with_globals<rustc_interface[e115f2a012085938]::interface::run_compiler<(), rustc_driver_impl[c1af299d1397a699]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[cbb3bcf71ac95dcb]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  42:     0x71462b97d437 - std::sys::pal::unix::thread::Thread::new::thread_start::h1a9d801f2bf05108
  43:     0x714625aa370a - <unknown>
  44:     0x714625b27aac - <unknown>
  45:                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 make sure that you have updated to the latest nightly

note: rustc 1.87.0-nightly (002da7682 2025-03-01) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z mir-enable-passes=+GVN -Z dump-mir-dir=dir

query stack during panic:
#0 [optimized_mir] optimizing MIR for `main`
#1 [check_mono_item] monomorphization-time checking
#2 [items_of_instance] collecting items used by `main`
#3 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
warning: 2 warnings emitted


@rustbot label +F-unsafe_binders

Metadata

Metadata

Labels

A-mir-opt-GVNArea: MIR opt Global Value Numbering (GVN)C-bugCategory: This is a bug.F-unsafe_binders`#![feature(unsafe_binders)]`I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions