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]: got a pointer where a ScalarInt was expected: alloc1 #131227

Open
1 of 4 tasks
shao-hua-li opened this issue Oct 4, 2024 · 1 comment
Open
1 of 4 tasks

[ICE]: got a pointer where a ScalarInt was expected: alloc1 #131227

shao-hua-li opened this issue Oct 4, 2024 · 1 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) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@shao-hua-li
Copy link

shao-hua-li commented Oct 4, 2024

pub static mut G: i32 = 0;
fn myfunc() -> i32 {
    let var: *mut i32 = &raw mut G;
    if !var.is_null() {
        return 0;
    }
    return 0;
}
pub fn main() {
    myfunc();
}

Reproduce command:

% rustc -Zmir-opt-level=3 test.rs

Affected release channels

  • Previous Stable
  • Current Stable
  • Current Beta
  • Current Nightly

Rust Version

rustc 1.83.0-nightly (9ff5fc4 2024-10-03)
binary: rustc
commit-hash: 9ff5fc4
commit-date: 2024-10-03
host: x86_64-unknown-linux-gnu
release: 1.83.0-nightly
LLVM version: 19.1.0

Current error output

No response

Backtrace

thread 'rustc' panicked at /rustc/9ff5fc4ffbbe1e911527aa054e789b05ae55ffcc/compiler/rustc_middle/src/mir/interpret/value.rs:325:34:
got a pointer where a ScalarInt was expected: alloc1
stack backtrace:
   0:     0x7f20fdd2408a - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h3b6d1d28b5b6e65b
   1:     0x7f20fe403426 - core::fmt::write::h7a8a3ad59835f2ef
   2:     0x7f20ff5dfc51 - std::io::Write::write_fmt::hc62d2f588923efbb
   3:     0x7f20fdd23ee2 - std::sys::backtrace::BacktraceLock::print::h38186afb7c6db19d
   4:     0x7f20fdd263b6 - std::panicking::default_hook::{{closure}}::hece6df33ae13135f
   5:     0x7f20fdd26200 - std::panicking::default_hook::h85d65eeb0b80ced5
   6:     0x7f20fcdd95ff - std[cd7b2798f3b81142]::panicking::update_hook::<alloc[f7cca1303983c8a6]::boxed::Box<rustc_driver_impl[8e1f195701ddac20]::install_ice_hook::{closure#0}>>::{closure#0}
   7:     0x7f20fdd26ac8 - std::panicking::rust_panic_with_hook::h92400aa23d63d1f5
   8:     0x7f20fdd2689a - std::panicking::begin_panic_handler::{{closure}}::hde4c33a0ad0f60a3
   9:     0x7f20fdd24539 - std::sys::backtrace::__rust_end_short_backtrace::hf3e72f3e3322fede
  10:     0x7f20fdd2655c - rust_begin_unwind
  11:     0x7f20faac31d0 - core::panicking::panic_fmt::h2a4ff6d97036dfe3
  12:     0x7f20fab80c06 - core::result::unwrap_failed::hd57aee752940fd95
  13:     0x7f20fd5f546a - <rustc_mir_transform[d0cd16a73a2ad177]::dataflow_const_prop::ConstAnalysis as rustc_mir_dataflow[f453f9888ca77c48]::value_analysis::ValueAnalysis>::handle_switch_int
  14:     0x7f20fd63ae50 - <rustc_mir_transform[d0cd16a73a2ad177]::dataflow_const_prop::DataflowConstProp as rustc_mir_transform[d0cd16a73a2ad177]::pass_manager::MirPass>::run_pass
  15:     0x7f20fe40b74d - rustc_mir_transform[d0cd16a73a2ad177]::pass_manager::run_passes_inner
  16:     0x7f20fe63e5e2 - rustc_mir_transform[d0cd16a73a2ad177]::optimized_mir
  17:     0x7f20fe63cea1 - rustc_query_impl[39ec3e70030e377d]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[39ec3e70030e377d]::query_impl::optimized_mir::dynamic_query::{closure#2}::{closure#0}, rustc_middle[a298ae4101b11455]::query::erase::Erased<[u8; 8usize]>>
  18:     0x7f20fe64507c - rustc_query_system[390f35925eb9a656]::query::plumbing::try_execute_query::<rustc_query_impl[39ec3e70030e377d]::DynamicConfig<rustc_query_system[390f35925eb9a656]::query::caches::DefIdCache<rustc_middle[a298ae4101b11455]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[39ec3e70030e377d]::plumbing::QueryCtxt, false>
  19:     0x7f20fe644633 - rustc_query_impl[39ec3e70030e377d]::query_impl::optimized_mir::get_query_non_incr::__rust_end_short_backtrace
  20:     0x7f20fe42f956 - rustc_middle[a298ae4101b11455]::query::plumbing::query_get_at::<rustc_query_system[390f35925eb9a656]::query::caches::DefIdCache<rustc_middle[a298ae4101b11455]::query::erase::Erased<[u8; 8usize]>>>
  21:     0x7f20fb976ff4 - rustc_mir_transform[d0cd16a73a2ad177]::cross_crate_inline::cross_crate_inlinable
  22:     0x7f20fe814185 - rustc_query_impl[39ec3e70030e377d]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[39ec3e70030e377d]::query_impl::cross_crate_inlinable::dynamic_query::{closure#2}::{closure#0}, rustc_middle[a298ae4101b11455]::query::erase::Erased<[u8; 1usize]>>
  23:     0x7f20fe812550 - rustc_query_system[390f35925eb9a656]::query::plumbing::try_execute_query::<rustc_query_impl[39ec3e70030e377d]::DynamicConfig<rustc_query_system[390f35925eb9a656]::query::caches::DefIdCache<rustc_middle[a298ae4101b11455]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[39ec3e70030e377d]::plumbing::QueryCtxt, false>
  24:     0x7f20fe81210a - rustc_query_impl[39ec3e70030e377d]::query_impl::cross_crate_inlinable::get_query_non_incr::__rust_end_short_backtrace
  25:     0x7f20fe635344 - rustc_passes[2e0cef4168ee81e0]::reachable::recursively_reachable
  26:     0x7f20fe4f8c37 - rustc_passes[2e0cef4168ee81e0]::reachable::reachable_set
  27:     0x7f20ff2d4a38 - rustc_query_impl[39ec3e70030e377d]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[39ec3e70030e377d]::query_impl::reachable_set::dynamic_query::{closure#2}::{closure#0}, rustc_middle[a298ae4101b11455]::query::erase::Erased<[u8; 8usize]>>
  28:     0x7f20ff2d33b9 - rustc_query_system[390f35925eb9a656]::query::plumbing::try_execute_query::<rustc_query_impl[39ec3e70030e377d]::DynamicConfig<rustc_query_system[390f35925eb9a656]::query::caches::SingleCache<rustc_middle[a298ae4101b11455]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[39ec3e70030e377d]::plumbing::QueryCtxt, false>
  29:     0x7f20ff2d2bde - rustc_query_impl[39ec3e70030e377d]::query_impl::reachable_set::get_query_non_incr::__rust_end_short_backtrace
  30:     0x7f20fef6884f - rustc_codegen_ssa[90ffdf4001995e6a]::back::symbol_export::reachable_non_generics_provider
  31:     0x7f20ff12fcfa - rustc_query_impl[39ec3e70030e377d]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[39ec3e70030e377d]::query_impl::reachable_non_generics::dynamic_query::{closure#2}::{closure#0}, rustc_middle[a298ae4101b11455]::query::erase::Erased<[u8; 8usize]>>
  32:     0x7f20ff12d460 - rustc_query_system[390f35925eb9a656]::query::plumbing::try_execute_query::<rustc_query_impl[39ec3e70030e377d]::DynamicConfig<rustc_query_system[390f35925eb9a656]::query::caches::VecCache<rustc_span[daf831eaae62485]::def_id::CrateNum, rustc_middle[a298ae4101b11455]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[39ec3e70030e377d]::plumbing::QueryCtxt, false>
  33:     0x7f20ff12d0e8 - rustc_query_impl[39ec3e70030e377d]::query_impl::reachable_non_generics::get_query_non_incr::__rust_end_short_backtrace
  34:     0x7f20fe8103d0 - rustc_middle[a298ae4101b11455]::query::plumbing::query_get_at::<rustc_query_system[390f35925eb9a656]::query::caches::VecCache<rustc_span[daf831eaae62485]::def_id::CrateNum, rustc_middle[a298ae4101b11455]::query::erase::Erased<[u8; 8usize]>>>
  35:     0x7f20fe810241 - rustc_codegen_ssa[90ffdf4001995e6a]::back::symbol_export::is_reachable_non_generic_provider_local
  36:     0x7f20fe811c63 - rustc_query_impl[39ec3e70030e377d]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[39ec3e70030e377d]::query_impl::is_reachable_non_generic::dynamic_query::{closure#2}::{closure#0}, rustc_middle[a298ae4101b11455]::query::erase::Erased<[u8; 1usize]>>
  37:     0x7f20fe812550 - rustc_query_system[390f35925eb9a656]::query::plumbing::try_execute_query::<rustc_query_impl[39ec3e70030e377d]::DynamicConfig<rustc_query_system[390f35925eb9a656]::query::caches::DefIdCache<rustc_middle[a298ae4101b11455]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[39ec3e70030e377d]::plumbing::QueryCtxt, false>
  38:     0x7f20fe811eca - rustc_query_impl[39ec3e70030e377d]::query_impl::is_reachable_non_generic::get_query_non_incr::__rust_end_short_backtrace
  39:     0x7f20fe633ce5 - <rustc_monomorphize[2200963646303804]::collector::RootCollector>::push_if_root
  40:     0x7f20feca2438 - rustc_monomorphize[2200963646303804]::partitioning::collect_and_partition_mono_items
  41:     0x7f20ff2d0424 - rustc_query_impl[39ec3e70030e377d]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[39ec3e70030e377d]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2}::{closure#0}, rustc_middle[a298ae4101b11455]::query::erase::Erased<[u8; 24usize]>>
  42:     0x7f20ff2d0409 - <rustc_query_impl[39ec3e70030e377d]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2} as core[5506f1b83e435595]::ops::function::FnOnce<(rustc_middle[a298ae4101b11455]::ty::context::TyCtxt, ())>>::call_once
  43:     0x7f20ff2cffc9 - rustc_query_system[390f35925eb9a656]::query::plumbing::try_execute_query::<rustc_query_impl[39ec3e70030e377d]::DynamicConfig<rustc_query_system[390f35925eb9a656]::query::caches::SingleCache<rustc_middle[a298ae4101b11455]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[39ec3e70030e377d]::plumbing::QueryCtxt, false>
  44:     0x7f20ff2cfce1 - rustc_query_impl[39ec3e70030e377d]::query_impl::collect_and_partition_mono_items::get_query_non_incr::__rust_end_short_backtrace
  45:     0x7f20ff2f4e41 - <rustc_codegen_llvm[f184af9d49f277d7]::LlvmCodegenBackend as rustc_codegen_ssa[90ffdf4001995e6a]::traits::backend::CodegenBackend>::codegen_crate
  46:     0x7f20ff437930 - <rustc_interface[5a058489867e71e6]::queries::Linker>::codegen_and_build_linker
  47:     0x7f20ff14410b - rustc_interface[5a058489867e71e6]::interface::run_compiler::<core[5506f1b83e435595]::result::Result<(), rustc_span[daf831eaae62485]::ErrorGuaranteed>, rustc_driver_impl[8e1f195701ddac20]::run_compiler::{closure#0}>::{closure#1}
  48:     0x7f20ff292750 - std[cd7b2798f3b81142]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[5a058489867e71e6]::util::run_in_thread_with_globals<rustc_interface[5a058489867e71e6]::util::run_in_thread_pool_with_globals<rustc_interface[5a058489867e71e6]::interface::run_compiler<core[5506f1b83e435595]::result::Result<(), rustc_span[daf831eaae62485]::ErrorGuaranteed>, rustc_driver_impl[8e1f195701ddac20]::run_compiler::{closure#0}>::{closure#1}, core[5506f1b83e435595]::result::Result<(), rustc_span[daf831eaae62485]::ErrorGuaranteed>>::{closure#0}, core[5506f1b83e435595]::result::Result<(), rustc_span[daf831eaae62485]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[5506f1b83e435595]::result::Result<(), rustc_span[daf831eaae62485]::ErrorGuaranteed>>
  49:     0x7f20ff292e17 - <<std[cd7b2798f3b81142]::thread::Builder>::spawn_unchecked_<rustc_interface[5a058489867e71e6]::util::run_in_thread_with_globals<rustc_interface[5a058489867e71e6]::util::run_in_thread_pool_with_globals<rustc_interface[5a058489867e71e6]::interface::run_compiler<core[5506f1b83e435595]::result::Result<(), rustc_span[daf831eaae62485]::ErrorGuaranteed>, rustc_driver_impl[8e1f195701ddac20]::run_compiler::{closure#0}>::{closure#1}, core[5506f1b83e435595]::result::Result<(), rustc_span[daf831eaae62485]::ErrorGuaranteed>>::{closure#0}, core[5506f1b83e435595]::result::Result<(), rustc_span[daf831eaae62485]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[5506f1b83e435595]::result::Result<(), rustc_span[daf831eaae62485]::ErrorGuaranteed>>::{closure#1} as core[5506f1b83e435595]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  50:     0x7f20ff293d01 - std::sys::pal::unix::thread::Thread::new::thread_start::he8cbd5378a86c4f4
  51:     0x7f20f9494ac3 - start_thread
                               at ./nptl/pthread_create.c:442:8
  52:     0x7f20f9526660 - __clone3
                               at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
  53:                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: please attach the file at `/home/shaohua/disk/research/codes/rustfuzz/csmith2rust/debug_crash/cargo_template/rustc-ice-2024-10-04T07_33_59-1969026.txt` to your bug report

note: compiler flags: -Z mir-opt-level=3

query stack during panic:
#0 [optimized_mir] optimizing MIR for `main`
#1 [cross_crate_inlinable] whether the item should be made inlinable across crates
#2 [reachable_set] reachability
#3 [reachable_non_generics] looking up the exported symbols of a crate
#4 [is_reachable_non_generic] checking whether `myfunc` is an exported symbol
#5 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
@shao-hua-li shao-hua-li 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 Oct 4, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 4, 2024
@cyrgani
Copy link
Contributor

cyrgani commented Oct 4, 2024

Slightly more reduced:

static mut G: () = ();

fn myfunc() -> i32 {
    let var = &raw mut G;
    if var.is_null() {
        return 0;
    }
    0
}

fn main() {
    myfunc();
}

@jieyouxu jieyouxu added A-mir-opt Area: MIR optimizations S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue labels Oct 4, 2024
@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 4, 2024
@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Oct 12, 2024
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) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue 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

6 participants