Skip to content

ICE: cannot read from extern static #2234

Closed
@matthiaskrgr

Description

@matthiaskrgr

code from src/test/ui/consts/ice-zst-static-access.rs

// This is a regression test for ICEs from
// https://github.com/rust-lang/rust/issues/71612
// and
// https://github.com/rust-lang/rust/issues/71709

#[derive(Copy, Clone)]
pub struct Glfw;

static mut GLFW: Option<Glfw> = None;
pub fn new() -> Glfw {
    unsafe {
        if let Some(glfw) = GLFW {
            return glfw;
        } else {
            todo!()
        }
    };
}

extern "C" {
    static _dispatch_queue_attr_concurrent: [u8; 0];
}

static DISPATCH_QUEUE_CONCURRENT: &'static [u8; 0] =
    unsafe { &_dispatch_queue_attr_concurrent };

fn main() {
    *DISPATCH_QUEUE_CONCURRENT;
    new();
}

miri panics here:

warning: unused unary operation that must be used
  --> src/main.rs:28:5
   |
28 |     *DISPATCH_QUEUE_CONCURRENT;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^ the unary operation produces a value
   |
   = note: `#[warn(unused_must_use)]` on by default
help: use `let _ = ...` to ignore the resulting value
   |
28 |     let _ = *DISPATCH_QUEUE_CONCURRENT;
   |     +++++++

thread 'rustc' panicked at 'Error should never be raised by Miri: cannot read from extern static (DefId(0:6 ~ mi[4f9b]::{extern#0}::_dispatch_queue_attr_concurrent))', src/tools/miri/src/diagnostics.rs:236:21
stack backtrace:
   0:     0x7fc6d669e21d - std::backtrace_rs::backtrace::libunwind::trace::h58f7ccf05e6e2202
                               at /rustc/ca122c7ebb3ab50149c9d3d24ddb59c252b32272/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7fc6d669e21d - std::backtrace_rs::backtrace::trace_unsynchronized::h6818d5037aac2151
                               at /rustc/ca122c7ebb3ab50149c9d3d24ddb59c252b32272/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7fc6d669e21d - std::sys_common::backtrace::_print_fmt::h7e9e91520c325876
                               at /rustc/ca122c7ebb3ab50149c9d3d24ddb59c252b32272/library/std/src/sys_common/backtrace.rs:66:5
   3:     0x7fc6d669e21d - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hb3419ccbd7447054
                               at /rustc/ca122c7ebb3ab50149c9d3d24ddb59c252b32272/library/std/src/sys_common/backtrace.rs:45:22
   4:     0x7fc6d66fa00c - core::fmt::write::hde8d85d5cf122740
                               at /rustc/ca122c7ebb3ab50149c9d3d24ddb59c252b32272/library/core/src/fmt/mod.rs:1196:17
   5:     0x7fc6d668f911 - std::io::Write::write_fmt::h1a964cb20becd056
                               at /rustc/ca122c7ebb3ab50149c9d3d24ddb59c252b32272/library/std/src/io/mod.rs:1654:15
   6:     0x7fc6d66a0ef5 - std::sys_common::backtrace::_print::h1e0d80c90ae8064d
                               at /rustc/ca122c7ebb3ab50149c9d3d24ddb59c252b32272/library/std/src/sys_common/backtrace.rs:48:5
   7:     0x7fc6d66a0ef5 - std::sys_common::backtrace::print::h28b1535981317802
                               at /rustc/ca122c7ebb3ab50149c9d3d24ddb59c252b32272/library/std/src/sys_common/backtrace.rs:35:9
   8:     0x7fc6d66a0ef5 - std::panicking::default_hook::{{closure}}::hd76d7ce191ece66f
                               at /rustc/ca122c7ebb3ab50149c9d3d24ddb59c252b32272/library/std/src/panicking.rs:295:22
   9:     0x7fc6d66a0c16 - std::panicking::default_hook::h02e21fa5aac93eac
                               at /rustc/ca122c7ebb3ab50149c9d3d24ddb59c252b32272/library/std/src/panicking.rs:314:9
  10:     0x7fc6d6efa041 - rustc_driver[84b62567f2ed5d49]::DEFAULT_HOOK::{closure#0}::{closure#0}
  11:     0x7fc6d66a15ca - std::panicking::rust_panic_with_hook::h2111e62403fb1455
                               at /rustc/ca122c7ebb3ab50149c9d3d24ddb59c252b32272/library/std/src/panicking.rs:702:17
  12:     0x7fc6d66a1407 - std::panicking::begin_panic_handler::{{closure}}::ha3b53a10dc4480d8
                               at /rustc/ca122c7ebb3ab50149c9d3d24ddb59c252b32272/library/std/src/panicking.rs:588:13
  13:     0x7fc6d669e6d4 - std::sys_common::backtrace::__rust_end_short_backtrace::h220589fe699b245e
                               at /rustc/ca122c7ebb3ab50149c9d3d24ddb59c252b32272/library/std/src/sys_common/backtrace.rs:138:18
  14:     0x7fc6d66a1139 - rust_begin_unwind
                               at /rustc/ca122c7ebb3ab50149c9d3d24ddb59c252b32272/library/std/src/panicking.rs:584:5
  15:     0x7fc6d6666343 - core::panicking::panic_fmt::hd5d5fec6a928eecd
                               at /rustc/ca122c7ebb3ab50149c9d3d24ddb59c252b32272/library/core/src/panicking.rs:142:14
  16:     0x55d8cd1f7dd4 - miri[6fa434adb66cc6f5]::diagnostics::report_error
  17:     0x55d8cd0fcc65 - miri[6fa434adb66cc6f5]::eval::eval_entry
  18:     0x55d8cd068c7a - <rustc_interface[207a0d5049d4199e]::passes::QueryContext>::enter::<<miri[86decc69f57428a8]::MiriCompilerCalls as rustc_driver[84b62567f2ed5d49]::Callbacks>::after_analysis::{closure#0}, ()>
  19:     0x55d8cd06b75f - <miri[86decc69f57428a8]::MiriCompilerCalls as rustc_driver[84b62567f2ed5d49]::Callbacks>::after_analysis
  20:     0x7fc6d90a06cc - <rustc_interface[207a0d5049d4199e]::interface::Compiler>::enter::<rustc_driver[84b62567f2ed5d49]::run_compiler::{closure#1}::{closure#2}, core[be71da1b78cea8d]::result::Result<core[be71da1b78cea8d]::option::Option<rustc_interface[207a0d5049d4199e]::queries::Linker>, rustc_errors[d790e5a717e9604b]::ErrorGuaranteed>>
  21:     0x7fc6d90c9d3f - rustc_span[45dafd7c97e42da1]::with_source_map::<core[be71da1b78cea8d]::result::Result<(), rustc_errors[d790e5a717e9604b]::ErrorGuaranteed>, rustc_interface[207a0d5049d4199e]::interface::create_compiler_and_run<core[be71da1b78cea8d]::result::Result<(), rustc_errors[d790e5a717e9604b]::ErrorGuaranteed>, rustc_driver[84b62567f2ed5d49]::run_compiler::{closure#1}>::{closure#1}>
  22:     0x7fc6d90a1542 - <scoped_tls[b8e034abe4adce2d]::ScopedKey<rustc_span[45dafd7c97e42da1]::SessionGlobals>>::set::<rustc_interface[207a0d5049d4199e]::interface::run_compiler<core[be71da1b78cea8d]::result::Result<(), rustc_errors[d790e5a717e9604b]::ErrorGuaranteed>, rustc_driver[84b62567f2ed5d49]::run_compiler::{closure#1}>::{closure#0}, core[be71da1b78cea8d]::result::Result<(), rustc_errors[d790e5a717e9604b]::ErrorGuaranteed>>
  23:     0x7fc6d90b6b7f - std[afa78adc105b1c86]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[207a0d5049d4199e]::util::run_in_thread_pool_with_globals<rustc_interface[207a0d5049d4199e]::interface::run_compiler<core[be71da1b78cea8d]::result::Result<(), rustc_errors[d790e5a717e9604b]::ErrorGuaranteed>, rustc_driver[84b62567f2ed5d49]::run_compiler::{closure#1}>::{closure#0}, core[be71da1b78cea8d]::result::Result<(), rustc_errors[d790e5a717e9604b]::ErrorGuaranteed>>::{closure#0}, core[be71da1b78cea8d]::result::Result<(), rustc_errors[d790e5a717e9604b]::ErrorGuaranteed>>
  24:     0x7fc6d90b6cd9 - <<std[afa78adc105b1c86]::thread::Builder>::spawn_unchecked_<rustc_interface[207a0d5049d4199e]::util::run_in_thread_pool_with_globals<rustc_interface[207a0d5049d4199e]::interface::run_compiler<core[be71da1b78cea8d]::result::Result<(), rustc_errors[d790e5a717e9604b]::ErrorGuaranteed>, rustc_driver[84b62567f2ed5d49]::run_compiler::{closure#1}>::{closure#0}, core[be71da1b78cea8d]::result::Result<(), rustc_errors[d790e5a717e9604b]::ErrorGuaranteed>>::{closure#0}, core[be71da1b78cea8d]::result::Result<(), rustc_errors[d790e5a717e9604b]::ErrorGuaranteed>>::{closure#1} as core[be71da1b78cea8d]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  25:     0x7fc6d66ab4f3 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h689e1c39ea398210
                               at /rustc/ca122c7ebb3ab50149c9d3d24ddb59c252b32272/library/alloc/src/boxed.rs:1951:9
  26:     0x7fc6d66ab4f3 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h6aea3b7ce18650de
                               at /rustc/ca122c7ebb3ab50149c9d3d24ddb59c252b32272/library/alloc/src/boxed.rs:1951:9
  27:     0x7fc6d66ab4f3 - std::sys::unix::thread::Thread::new::thread_start::h2e612d703ca53c2a
                               at /rustc/ca122c7ebb3ab50149c9d3d24ddb59c252b32272/library/std/src/sys/unix/thread.rs:108:17
  28:     0x7fc6d639854d - <unknown>
  29:     0x7fc6d641db14 - clone
  30:                0x0 - <unknown>

error: internal compiler error: unexpected panic

note: 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.63.0-nightly (ca122c7eb 2022-06-13) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C incremental -C target-cpu=native

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack
warning: 1 warning emitted

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions