rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
97.63k stars 12.63k forks source link

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

Open shao-hua-li opened 1 week ago

shao-hua-li commented 1 week ago
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

Rust Version

rustc 1.83.0-nightly (9ff5fc4ff 2024-10-03) binary: rustc commit-hash: 9ff5fc4ffbbe1e911527aa054e789b05ae55ffcc 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 - ::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::>::{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 - ::handle_switch_int 14: 0x7f20fd63ae50 - ::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::> 18: 0x7f20fe64507c - rustc_query_system[390f35925eb9a656]::query::plumbing::try_execute_query::>, 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::>> 21: 0x7f20fb976ff4 - rustc_mir_transform[d0cd16a73a2ad177]::cross_crate_inline::cross_crate_inlinable 22: 0x7f20fe814185 - rustc_query_impl[39ec3e70030e377d]::plumbing::__rust_begin_short_backtrace::> 23: 0x7f20fe812550 - rustc_query_system[390f35925eb9a656]::query::plumbing::try_execute_query::>, 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::> 28: 0x7f20ff2d33b9 - rustc_query_system[390f35925eb9a656]::query::plumbing::try_execute_query::>, 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::> 32: 0x7f20ff12d460 - rustc_query_system[390f35925eb9a656]::query::plumbing::try_execute_query::>, 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::>> 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::> 37: 0x7f20fe812550 - rustc_query_system[390f35925eb9a656]::query::plumbing::try_execute_query::>, 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 - ::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::> 42: 0x7f20ff2d0409 - >::call_once 43: 0x7f20ff2cffc9 - rustc_query_system[390f35925eb9a656]::query::plumbing::try_execute_query::>, 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 - ::codegen_crate 46: 0x7f20ff437930 - ::codegen_and_build_linker 47: 0x7f20ff14410b - rustc_interface[5a058489867e71e6]::interface::run_compiler::, rustc_driver_impl[8e1f195701ddac20]::run_compiler::{closure#0}>::{closure#1} 48: 0x7f20ff292750 - std[cd7b2798f3b81142]::sys::backtrace::__rust_begin_short_backtrace::, 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 - <::spawn_unchecked_, 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 - 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 ```
cyrgani commented 1 week ago

Slightly more reduced:

static mut G: () = ();

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

fn main() {
    myfunc();
}