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: Cannot Eq compare incompatible types *mut T/#0 and *const T/#0 #127089

Closed
chenzhuoyu opened this issue Jun 28, 2024 · 2 comments · Fixed by #127105
Closed

ICE: Cannot Eq compare incompatible types *mut T/#0 and *const T/#0 #127089

chenzhuoyu opened this issue Jun 28, 2024 · 2 comments · Fixed by #127105
Labels
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

@chenzhuoyu
Copy link

Compiling the following code with rustc -C opt-level=3 -o main main.rs results in ICE.

Strangely, this code compiles fine without -C opt-level=3. Replace std::ptr::eq with plain == comparison also works.

Code

main.rs:

#![feature(strict_provenance)]

struct Foo<T>(std::marker::PhantomData<T>);

impl<T> Foo<T> {
    const SENTINEL: *mut T = std::ptr::dangling_mut();

    fn cmp_ptr(a: *mut T) -> bool {
        std::ptr::eq(a, Self::SENTINEL)
    }
}

pub fn main() {
    Foo::<u8>::cmp_ptr(std::ptr::dangling_mut());
}

Meta

rustc --version --verbose:

rustc 1.81.0-nightly (9c3bc805d 2024-06-27)
binary: rustc
commit-hash: 9c3bc805dd9cb84019c124b9a50fdff1e62a7ec9
commit-date: 2024-06-27
host: aarch64-apple-darwin
release: 1.81.0-nightly
LLVM version: 18.1.7

Error output

thread 'rustc' panicked at compiler/rustc_mir_transform/src/validate.rs:94:25:
broken MIR in Item(DefId(0:10 ~ main[a0a6]::{impl#0}::cmp_ptr)) (after phase change to runtime-optimized) at bb0[2]:
Cannot Eq compare incompatible types *mut T/#0 and *const T/#0
Backtrace

thread 'rustc' panicked at compiler/rustc_mir_transform/src/validate.rs:94:25:
broken MIR in Item(DefId(0:10 ~ main[0f07]::{impl#0}::cmp_ptr)) (after phase change to runtime-optimized) at bb0[2]:
Cannot Eq compare incompatible types *mut T/#0 and *const T/#0
stack backtrace:
   0:        0x10166abb0 - <std::sys::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::he3d597287e17a7dd
   1:        0x1016ae128 - core::fmt::write::h03b4629f44ceab5b
   2:        0x101660d0c - std::io::Write::write_fmt::h87342a3edd7134e6
   3:        0x10166aa08 - std::sys::backtrace::print::ha920eaaf60abc78c
   4:        0x10166d018 - std::panicking::default_hook::{{closure}}::h7ad69dc6a5c53104
   5:        0x10166cce4 - std::panicking::default_hook::h9d08a9b346efd6d1
   6:        0x10b484d30 - std[76b399b4b9fa005f]::panicking::update_hook::<alloc[53949c4a0a9a41eb]::boxed::Box<rustc_driver_impl[e337739a2a22afd0]::install_ice_hook::{closure#0}>>::{closure#0}
   7:        0x10166db64 - std::panicking::rust_panic_with_hook::h84287953c8418b94
   8:        0x10166d474 - std::panicking::begin_panic_handler::{{closure}}::h398278ce2f98270b
   9:        0x10166b03c - std::sys::backtrace::__rust_end_short_backtrace::h999c20c26585ce7f
  10:        0x10166d180 - _rust_begin_unwind
  11:        0x1016c8940 - core::panicking::panic_fmt::h18805dc216586a3b
  12:        0x10c485220 - <rustc_mir_transform[a22c9e098425d728]::validate::CfgChecker>::fail::<alloc[53949c4a0a9a41eb]::string::String>
  13:        0x10c484a04 - <rustc_mir_transform[a22c9e098425d728]::validate::Validator as rustc_middle[a37ff32571d5c1a9]::mir::MirPass>::run_pass
  14:        0x10c47d0cc - rustc_mir_transform[a22c9e098425d728]::pass_manager::run_passes_inner
  15:        0x10c3431f8 - rustc_mir_transform[a22c9e098425d728]::optimized_mir
  16:        0x10c953634 - rustc_query_impl[a9de1c92a9de04a0]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a9de1c92a9de04a0]::query_impl::optimized_mir::dynamic_query::{closure#2}::{closure#0}, rustc_middle[a37ff32571d5c1a9]::query::erase::Erased<[u8; 8usize]>>
  17:        0x10cb02cf0 - <rustc_query_impl[a9de1c92a9de04a0]::query_impl::optimized_mir::dynamic_query::{closure#2} as core[d0cf843891889b67]::ops::function::FnOnce<(rustc_middle[a37ff32571d5c1a9]::ty::context::TyCtxt, rustc_span[19473d8b3fea81af]::def_id::DefId)>>::call_once
  18:        0x10c86bfe0 - rustc_query_system[e2da81a1c072113]::query::plumbing::try_execute_query::<rustc_query_impl[a9de1c92a9de04a0]::DynamicConfig<rustc_query_system[e2da81a1c072113]::query::caches::DefIdCache<rustc_middle[a37ff32571d5c1a9]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[a9de1c92a9de04a0]::plumbing::QueryCtxt, false>
  19:        0x10cb10ea0 - rustc_query_impl[a9de1c92a9de04a0]::query_impl::optimized_mir::get_query_non_incr::__rust_end_short_backtrace
  20:        0x10c4746b8 - rustc_middle[a37ff32571d5c1a9]::query::plumbing::query_get_at::<rustc_query_system[e2da81a1c072113]::query::caches::DefIdCache<rustc_middle[a37ff32571d5c1a9]::query::erase::Erased<[u8; 8usize]>>>
  21:        0x10c47eda4 - rustc_mir_transform[a22c9e098425d728]::cross_crate_inline::cross_crate_inlinable
  22:        0x10c957818 - rustc_query_impl[a9de1c92a9de04a0]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a9de1c92a9de04a0]::query_impl::cross_crate_inlinable::dynamic_query::{closure#2}::{closure#0}, rustc_middle[a37ff32571d5c1a9]::query::erase::Erased<[u8; 1usize]>>
  23:        0x10c9b6acc - <rustc_query_impl[a9de1c92a9de04a0]::query_impl::cross_crate_inlinable::dynamic_query::{closure#2} as core[d0cf843891889b67]::ops::function::FnOnce<(rustc_middle[a37ff32571d5c1a9]::ty::context::TyCtxt, rustc_span[19473d8b3fea81af]::def_id::DefId)>>::call_once
  24:        0x10c860ae8 - rustc_query_system[e2da81a1c072113]::query::plumbing::try_execute_query::<rustc_query_impl[a9de1c92a9de04a0]::DynamicConfig<rustc_query_system[e2da81a1c072113]::query::caches::DefIdCache<rustc_middle[a37ff32571d5c1a9]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[a9de1c92a9de04a0]::plumbing::QueryCtxt, false>
  25:        0x10cb39148 - rustc_query_impl[a9de1c92a9de04a0]::query_impl::cross_crate_inlinable::get_query_non_incr::__rust_end_short_backtrace
  26:        0x10c32c7f0 - rustc_middle[a37ff32571d5c1a9]::query::plumbing::query_get_at::<rustc_query_system[e2da81a1c072113]::query::caches::DefIdCache<rustc_middle[a37ff32571d5c1a9]::query::erase::Erased<[u8; 1usize]>>>
  27:        0x10c336090 - <rustc_mir_transform[a22c9e098425d728]::inline::Inliner>::try_inlining
  28:        0x10c335378 - <rustc_mir_transform[a22c9e098425d728]::inline::Inliner>::process_blocks
  29:        0x10c334da4 - <rustc_mir_transform[a22c9e098425d728]::inline::Inline as rustc_middle[a37ff32571d5c1a9]::mir::MirPass>::run_pass
  30:        0x10c47cbb4 - rustc_mir_transform[a22c9e098425d728]::pass_manager::run_passes_inner
  31:        0x10c3431f8 - rustc_mir_transform[a22c9e098425d728]::optimized_mir
  32:        0x10c953634 - rustc_query_impl[a9de1c92a9de04a0]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a9de1c92a9de04a0]::query_impl::optimized_mir::dynamic_query::{closure#2}::{closure#0}, rustc_middle[a37ff32571d5c1a9]::query::erase::Erased<[u8; 8usize]>>
  33:        0x10cb02cf0 - <rustc_query_impl[a9de1c92a9de04a0]::query_impl::optimized_mir::dynamic_query::{closure#2} as core[d0cf843891889b67]::ops::function::FnOnce<(rustc_middle[a37ff32571d5c1a9]::ty::context::TyCtxt, rustc_span[19473d8b3fea81af]::def_id::DefId)>>::call_once
  34:        0x10c86bfe0 - rustc_query_system[e2da81a1c072113]::query::plumbing::try_execute_query::<rustc_query_impl[a9de1c92a9de04a0]::DynamicConfig<rustc_query_system[e2da81a1c072113]::query::caches::DefIdCache<rustc_middle[a37ff32571d5c1a9]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[a9de1c92a9de04a0]::plumbing::QueryCtxt, false>
  35:        0x10cb10ea0 - rustc_query_impl[a9de1c92a9de04a0]::query_impl::optimized_mir::get_query_non_incr::__rust_end_short_backtrace
  36:        0x10c052394 - rustc_middle[a37ff32571d5c1a9]::query::plumbing::query_get_at::<rustc_query_system[e2da81a1c072113]::query::caches::DefIdCache<rustc_middle[a37ff32571d5c1a9]::query::erase::Erased<[u8; 8usize]>>>
  37:        0x10c0599b0 - <rustc_middle[a37ff32571d5c1a9]::ty::context::TyCtxt>::instance_mir
  38:        0x10c507700 - rustc_monomorphize[148aaa952e24e330]::collector::collect_items_of_instance
  39:        0x10c5067f0 - rustc_monomorphize[148aaa952e24e330]::collector::collect_items_rec
  40:        0x10c5456fc - std[76b399b4b9fa005f]::panicking::try::<(), core[d0cf843891889b67]::panic::unwind_safe::AssertUnwindSafe<rustc_data_structures[b2b8ae2df7595792]::sync::parallel::enabled::par_for_each_in<rustc_middle[a37ff32571d5c1a9]::mir::mono::MonoItem, alloc[53949c4a0a9a41eb]::vec::Vec<rustc_middle[a37ff32571d5c1a9]::mir::mono::MonoItem>, rustc_monomorphize[148aaa952e24e330]::collector::collect_crate_mono_items::{closure#1}::{closure#0}>::{closure#0}::{closure#1}::{closure#0}>>
  41:        0x10c53432c - <rustc_data_structures[b2b8ae2df7595792]::sync::parallel::ParallelGuard>::run::<(), rustc_data_structures[b2b8ae2df7595792]::sync::parallel::enabled::par_for_each_in<rustc_middle[a37ff32571d5c1a9]::mir::mono::MonoItem, alloc[53949c4a0a9a41eb]::vec::Vec<rustc_middle[a37ff32571d5c1a9]::mir::mono::MonoItem>, rustc_monomorphize[148aaa952e24e330]::collector::collect_crate_mono_items::{closure#1}::{closure#0}>::{closure#0}::{closure#1}::{closure#0}>
  42:        0x10c5452a0 - <rustc_session[4e5213968b08c628]::session::Session>::time::<(), rustc_monomorphize[148aaa952e24e330]::collector::collect_crate_mono_items::{closure#1}>
  43:        0x10c508f74 - rustc_monomorphize[148aaa952e24e330]::collector::collect_crate_mono_items
  44:        0x10c512d34 - rustc_monomorphize[148aaa952e24e330]::partitioning::collect_and_partition_mono_items
  45:        0x10c95a1cc - rustc_query_impl[a9de1c92a9de04a0]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a9de1c92a9de04a0]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2}::{closure#0}, rustc_middle[a37ff32571d5c1a9]::query::erase::Erased<[u8; 24usize]>>
  46:        0x10ca6c160 - <rustc_query_impl[a9de1c92a9de04a0]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2} as core[d0cf843891889b67]::ops::function::FnOnce<(rustc_middle[a37ff32571d5c1a9]::ty::context::TyCtxt, ())>>::call_once
  47:        0x10c873b14 - rustc_query_system[e2da81a1c072113]::query::plumbing::try_execute_query::<rustc_query_impl[a9de1c92a9de04a0]::DynamicConfig<rustc_query_system[e2da81a1c072113]::query::caches::SingleCache<rustc_middle[a37ff32571d5c1a9]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[a9de1c92a9de04a0]::plumbing::QueryCtxt, false>
  48:        0x10cb3259c - rustc_query_impl[a9de1c92a9de04a0]::query_impl::collect_and_partition_mono_items::get_query_non_incr::__rust_end_short_backtrace
  49:        0x10b105728 - rustc_codegen_ssa[e3e96a407e96fbaf]::base::codegen_crate::<rustc_codegen_llvm[eac619daf28d4c]::LlvmCodegenBackend>
  50:        0x10b1c4100 - <rustc_codegen_llvm[eac619daf28d4c]::LlvmCodegenBackend as rustc_codegen_ssa[e3e96a407e96fbaf]::traits::backend::CodegenBackend>::codegen_crate
  51:        0x10bcf39cc - <rustc_session[4e5213968b08c628]::session::Session>::time::<alloc[53949c4a0a9a41eb]::boxed::Box<dyn core[d0cf843891889b67]::any::Any>, rustc_interface[859372deaefb7862]::passes::start_codegen::{closure#0}>
  52:        0x10bdb824c - rustc_interface[859372deaefb7862]::passes::start_codegen
  53:        0x10bd1be88 - <rustc_interface[859372deaefb7862]::queries::Queries>::codegen_and_build_linker
  54:        0x10b436298 - <rustc_interface[859372deaefb7862]::interface::Compiler>::enter::<rustc_driver_impl[e337739a2a22afd0]::run_compiler::{closure#0}::{closure#1}, core[d0cf843891889b67]::result::Result<core[d0cf843891889b67]::option::Option<rustc_interface[859372deaefb7862]::queries::Linker>, rustc_span[19473d8b3fea81af]::ErrorGuaranteed>>
  55:        0x10b49ac6c - rustc_span[19473d8b3fea81af]::create_session_globals_then::<core[d0cf843891889b67]::result::Result<(), rustc_span[19473d8b3fea81af]::ErrorGuaranteed>, rustc_interface[859372deaefb7862]::util::run_in_thread_with_globals<rustc_interface[859372deaefb7862]::util::run_in_thread_pool_with_globals<rustc_interface[859372deaefb7862]::interface::run_compiler<core[d0cf843891889b67]::result::Result<(), rustc_span[19473d8b3fea81af]::ErrorGuaranteed>, rustc_driver_impl[e337739a2a22afd0]::run_compiler::{closure#0}>::{closure#1}, core[d0cf843891889b67]::result::Result<(), rustc_span[19473d8b3fea81af]::ErrorGuaranteed>>::{closure#0}, core[d0cf843891889b67]::result::Result<(), rustc_span[19473d8b3fea81af]::ErrorGuaranteed>>::{closure#0}::{closure#0}::{closure#0}>
  56:        0x10b468a4c - std[76b399b4b9fa005f]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[859372deaefb7862]::util::run_in_thread_with_globals<rustc_interface[859372deaefb7862]::util::run_in_thread_pool_with_globals<rustc_interface[859372deaefb7862]::interface::run_compiler<core[d0cf843891889b67]::result::Result<(), rustc_span[19473d8b3fea81af]::ErrorGuaranteed>, rustc_driver_impl[e337739a2a22afd0]::run_compiler::{closure#0}>::{closure#1}, core[d0cf843891889b67]::result::Result<(), rustc_span[19473d8b3fea81af]::ErrorGuaranteed>>::{closure#0}, core[d0cf843891889b67]::result::Result<(), rustc_span[19473d8b3fea81af]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[d0cf843891889b67]::result::Result<(), rustc_span[19473d8b3fea81af]::ErrorGuaranteed>>
  57:        0x10b42ebbc - <<std[76b399b4b9fa005f]::thread::Builder>::spawn_unchecked_<rustc_interface[859372deaefb7862]::util::run_in_thread_with_globals<rustc_interface[859372deaefb7862]::util::run_in_thread_pool_with_globals<rustc_interface[859372deaefb7862]::interface::run_compiler<core[d0cf843891889b67]::result::Result<(), rustc_span[19473d8b3fea81af]::ErrorGuaranteed>, rustc_driver_impl[e337739a2a22afd0]::run_compiler::{closure#0}>::{closure#1}, core[d0cf843891889b67]::result::Result<(), rustc_span[19473d8b3fea81af]::ErrorGuaranteed>>::{closure#0}, core[d0cf843891889b67]::result::Result<(), rustc_span[19473d8b3fea81af]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[d0cf843891889b67]::result::Result<(), rustc_span[19473d8b3fea81af]::ErrorGuaranteed>>::{closure#2} as core[d0cf843891889b67]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  58:        0x1016760b4 - std::sys::pal::unix::thread::Thread::new::thread_start::hd57c46075faf34b9
  59:        0x1917a2f94 - __pthread_joiner_wake

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: please attach the file at `/tmp/rustc-ice-2024-06-28T16_06_04-34433.txt` to your bug report

note: compiler flags: -C opt-level=3

query stack during panic:
#0 [optimized_mir] optimizing MIR for `<impl at main.rs:5:1: 5:15>::cmp_ptr`
#1 [cross_crate_inlinable] whether the item should be made inlinable across crates
end of query stack

rustc-ice-2024-06-28T16_06_04-34433.txt

@chenzhuoyu chenzhuoyu 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 Jun 28, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jun 28, 2024
@compiler-errors compiler-errors added the E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc label Jun 28, 2024
@lqd
Copy link
Member

lqd commented Jun 28, 2024

This seems to bisect to #126844 cc @scottmcm

@lqd lqd removed the E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc label Jun 28, 2024
@scottmcm
Copy link
Member

Thanks for the ping! I'll take a look.

I thought I'd checked for this with https://github.com/rust-lang/rust/pull/126844/files#diff-6202eda9e5f3c8b8a291cf165920ea8484c372002e485eafa920b319f7cb4dd3R1072, but clearly I missed something.

@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jun 29, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jul 1, 2024
Only update `Eq` operands in GVN if it can update both sides

Otherwise the types might not match

Fixes rust-lang#127089

r? mir-opt
@bors bors closed this as completed in 6938b4b Jul 1, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jul 1, 2024
Rollup merge of rust-lang#127105 - scottmcm:issue-127089, r=cjgillot

Only update `Eq` operands in GVN if it can update both sides

Otherwise the types might not match

Fixes rust-lang#127089

r? mir-opt
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. 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.

6 participants