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 in --emit mir: expected allocation ID to point to memory #66930

Closed
bjorn3 opened this issue Dec 1, 2019 · 14 comments · Fixed by #72682
Closed

ICE in --emit mir: expected allocation ID to point to memory #66930

bjorn3 opened this issue Dec 1, 2019 · 14 comments · Fixed by #72682
Labels
A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html A-pretty Area: Pretty printing (including `-Z unpretty`) C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. 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

@bjorn3
Copy link
Member

bjorn3 commented Dec 1, 2019

Minimal reproducer:

static UTF8_CHAR_WIDTH: [u8; 0] = [];

pub fn utf8_char_width(b: u8) -> usize {
    UTF8_CHAR_WIDTH[b as usize] as usize
}

Make sure to run rustc with --emit mir to reproduce!

original issue

error: internal compiler error: src/librustc/mir/interpret/mod.rs:473: expected allocation ID 337 to point to memory

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:892:9
stack backtrace:
   0: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
   1: core::fmt::write
   2: std::io::Write::write_fmt
   3: std::panicking::default_hook::{{closure}}
   4: std::panicking::default_hook
   5: rustc_driver::report_ice
   6: std::panicking::rust_panic_with_hook
   7: std::panicking::begin_panic
   8: rustc_errors::HandlerInner::bug
   9: rustc_errors::Handler::bug
  10: rustc::util::bug::opt_span_bug_fmt::{{closure}}
  11: rustc::ty::context::tls::with_opt::{{closure}}
  12: rustc::ty::context::tls::with_opt
  13: rustc::util::bug::opt_span_bug_fmt
  14: rustc::util::bug::bug_fmt
  15: <rustc::ty::print::pretty::FmtPrinter<F> as rustc::ty::print::Printer>::print_const
  16: rustc::ty::print::pretty::<impl core::fmt::Display for &rustc::ty::sty::Const>::fmt
  17: core::fmt::write
  18: core::fmt::Formatter::write_fmt
  19: <rustc::mir::Constant as core::fmt::Display>::fmt
  20: core::fmt::write
  21: core::fmt::Formatter::write_fmt
  22: <&T as core::fmt::Debug>::fmt
  23: core::fmt::write
  24: core::fmt::Formatter::write_fmt
  25: <rustc::mir::Operand as core::fmt::Debug>::fmt
  26: core::fmt::write
  27: core::fmt::Formatter::write_fmt
  28: <rustc::mir::Rvalue as core::fmt::Debug>::fmt
  29: core::fmt::write
  30: core::fmt::Formatter::write_fmt
  31: <rustc::mir::Statement as core::fmt::Debug>::fmt
  32: <&T as core::fmt::Debug>::fmt
  33: core::fmt::write
  34: alloc::fmt::format
  35: rustc_codegen_cranelift::base::trans_stmt
  36: rustc_codegen_cranelift::base::codegen_fn_content
  37: rustc_codegen_cranelift::base::trans_fn
  38: rustc_codegen_cranelift::driver::trans_mono_item
  39: rustc_codegen_cranelift::driver::codegen_mono_items::{{closure}}::{{closure}}
  40: rustc_codegen_cranelift::unimpl::try_unimpl::{{closure}}::{{closure}}
  41: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
  42: std::panicking::try::do_call
  43: __rust_maybe_catch_panic
  44: std::panicking::try
  45: std::panic::catch_unwind
  46: rustc_codegen_cranelift::unimpl::try_unimpl::{{closure}}
  47: std::thread::local::LocalKey<T>::try_with
  48: std::thread::local::LocalKey<T>::with
  49: rustc_codegen_cranelift::unimpl::try_unimpl
  50: rustc_codegen_cranelift::driver::codegen_mono_items::{{closure}}
  51: rustc_codegen_cranelift::driver::time
  52: rustc_codegen_cranelift::driver::codegen_mono_items
  53: rustc_codegen_cranelift::driver::codegen_cgus
  54: rustc_codegen_cranelift::driver::run_aot
  55: rustc_codegen_cranelift::driver::codegen_crate
  56: <rustc_codegen_cranelift::CraneliftCodegenBackend as rustc_codegen_utils::codegen_backend::CodegenBackend>::codegen_crate
  57: rustc_interface::passes::start_codegen::{{closure}}
  58: rustc_interface::passes::start_codegen
  59: rustc::ty::context::tls::enter_global
  60: rustc_interface::passes::BoxedGlobalCtxt::access::{{closure}}
  61: rustc_interface::passes::create_global_ctxt::{{closure}}
  62: rustc_interface::passes::BoxedGlobalCtxt::enter
  63: rustc_interface::queries::Query<T>::compute
  64: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::ongoing_codegen
  65: rustc_interface::interface::run_compiler_in_existing_thread_pool
  66: std::thread::local::LocalKey<T>::with
  67: scoped_tls::ScopedKey<T>::set
  68: syntax::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.41.0-nightly (25d8a9494 2019-11-29) running on x86_64-apple-darwin

note: compiler flags: -Z panic-abort-tests -Z codegen-backend=/Users/bjorn/Documents/rustc_codegen_cranelift/target/debug/librustc_codegen_cranelift.dylib -Z force-unstable-if-unmarked -C debuginfo=2 -C incremental -C panic=abort -C debuginfo=2 --crate-type lib

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

query stack during panic:
end of query stack
Instance { def: Item(DefId(0:6927 ~ core[c569]::str[0]::utf8_char_width[0])), substs: [] } _ZN4core3str15utf8_char_width17h59697a8cf43d24a0E
error: aborting due to previous error

error: could not compile `core`.

Using -Zmir-opt-level=0 doesn't fix this.

@bjorn3

This comment has been minimized.

@bjorn3

This comment has been minimized.

@jonas-schievink jonas-schievink added A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html A-pretty Area: Pretty printing (including `-Z unpretty`) 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 Dec 1, 2019
@Centril
Copy link
Contributor

Centril commented Dec 1, 2019

cc @eddyb

@eddyb

This comment has been minimized.

@JohnTitor
Copy link
Member

It seems like no longer ICE with latest nightly, I guess #67501 fixed this (CC: @oli-obk).
Marked as E-needstest

@JohnTitor JohnTitor added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Jan 11, 2020
@JohnTitor
Copy link
Member

@Alexendoo points out the second example hasn't been fixed yet, dropping E-needstest.

@JohnTitor JohnTitor removed the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Jan 11, 2020
@RalfJung
Copy link
Member

RalfJung commented Feb 28, 2020

Is the issue description still accurate? "Can't debug format a mir stmt in DefId" reminds me of a check that I added after we had some ICE issues with debug-printing DefIds.

But as far as I can see, no example mentioned here even triggers an ICE with that message.
The ICEs described here sound very different than that, they look like CTFE is not handling ZSTs properly somewhere.

@RalfJung
Copy link
Member

@Alexendoo points out the second example hasn't been fixed yet, dropping E-needstest.

I cannot reproduce the ICE on beta or nightly, so it looks pretty fixed to me.

@bjorn3 can you still reproduce this issue with latest nightly? The first backtrace has no code, so it is impossible to debug; the second backtrace (the one with self-contained code) does not seem to ICE any more.

@JohnTitor
Copy link
Member

I cannot reproduce the ICE on beta or nightly, so it looks pretty fixed to me.

Uhm? I don't think so, did you run with --emit=mir?

@RalfJung
Copy link
Member

Ah, I just ran on playground.

It would be good to have up-to-date reproduction instructions in the first post, and not just in the third post below a huge stacktrace.

@JohnTitor
Copy link
Member

It would be good to have up-to-date reproduction instructions in the first post, and not just in the third post below a huge stacktrace.

Yeah, but I don't have write access :/

@RalfJung
Copy link
Member

Yeah, but I don't have write access :/

Ouch, sorry. :( I didn't know.
I will update the OP.

@RalfJung
Copy link
Member

Here's a backtrace with debug info
thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:881:9
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /home/r/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.44/src/backtrace/libunwind.rs:86
   1: backtrace::backtrace::trace_unsynchronized
             at /home/r/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.44/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:1053
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1428
   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:204
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:224
  10: <alloc::boxed::Box<F> as core::ops::function::Fn<A>>::call
             at ./src/liballoc/boxed.rs:1031
  11: rustc_driver::report_ice
             at src/librustc_driver/lib.rs:1179
  12: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:474
  13: std::panicking::begin_panic
             at ./src/libstd/panicking.rs:397
  14: rustc_errors::HandlerInner::bug
             at src/librustc_errors/lib.rs:881
  15: rustc_errors::Handler::bug
             at src/librustc_errors/lib.rs:656
  16: rustc::util::bug::opt_span_bug_fmt::{{closure}}
             at src/librustc/util/bug.rs:36
  17: rustc::ty::context::tls::with_opt::{{closure}}
             at src/librustc/ty/context.rs:1829
  18: rustc::ty::context::tls::with_context_opt
             at src/librustc/ty/context.rs:1781
  19: rustc::ty::context::tls::with_opt
             at src/librustc/ty/context.rs:1829
  20: rustc::util::bug::opt_span_bug_fmt
             at src/librustc/util/bug.rs:32
  21: rustc::util::bug::bug_fmt
             at src/librustc/util/bug.rs:12
  22: rustc::mir::interpret::AllocMap::unwrap_memory
             at src/librustc/mir/interpret/mod.rs:482
  23: rustc::ty::print::pretty::PrettyPrinter::pretty_print_const_value
             at src/librustc/ty/print/pretty.rs:963
  24: rustc::ty::print::pretty::PrettyPrinter::pretty_print_const
             at src/librustc/ty/print/pretty.rs:882
  25: <rustc::ty::print::pretty::FmtPrinter<F> as rustc::ty::print::Printer>::print_const
             at src/librustc/ty/print/pretty.rs:1184
  26: <&rustc::ty::sty::Const as rustc::ty::print::Print<P>>::print
             at src/librustc/ty/print/mod.rs:345
  27: rustc::ty::print::pretty::<impl core::fmt::Display for &rustc::ty::sty::Const>::fmt::{{closure}}
             at src/librustc/ty/print/pretty.rs:1624
  28: rustc::ty::context::tls::with::{{closure}}
             at src/librustc/ty/context.rs:1819
  29: rustc::ty::context::tls::with_context::{{closure}}
             at src/librustc/ty/context.rs:1792
  30: rustc::ty::context::tls::with_context_opt
             at src/librustc/ty/context.rs:1781
  31: rustc::ty::context::tls::with_context
             at src/librustc/ty/context.rs:1792
  32: rustc::ty::context::tls::with
             at src/librustc/ty/context.rs:1819
  33: rustc::ty::print::pretty::<impl core::fmt::Display for &rustc::ty::sty::Const>::fmt
             at src/librustc/ty/print/pretty.rs:1623
  34: core::fmt::write
             at src/libcore/fmt/mod.rs:1053
  35: core::fmt::Formatter::write_fmt
             at src/libcore/fmt/mod.rs:1474
  36: <rustc::mir::Constant as core::fmt::Display>::fmt
             at ./src/libcore/fmt/mod.rs:0
  37: core::fmt::write
             at src/libcore/fmt/mod.rs:1053
  38: core::fmt::Formatter::write_fmt
             at src/libcore/fmt/mod.rs:1474
  39: <rustc::mir::Constant as core::fmt::Debug>::fmt
             at src/librustc/mir/mod.rs:2559
  40: core::fmt::write
             at src/libcore/fmt/mod.rs:1053
  41: core::fmt::Formatter::write_fmt
             at src/libcore/fmt/mod.rs:1474
  42: <rustc::mir::Operand as core::fmt::Debug>::fmt
             at src/librustc/mir/mod.rs:0
  43: core::fmt::write
             at src/libcore/fmt/mod.rs:1053
  44: core::fmt::Formatter::write_fmt
             at src/libcore/fmt/mod.rs:1474
  45: <rustc::mir::Rvalue as core::fmt::Debug>::fmt
             at src/librustc/mir/mod.rs:0
  46: core::fmt::write
             at src/libcore/fmt/mod.rs:1053
  47: core::fmt::Formatter::write_fmt
             at src/libcore/fmt/mod.rs:1474
  48: <rustc::mir::Statement as core::fmt::Debug>::fmt
             at src/librustc/mir/mod.rs:0
  49: core::fmt::run
             at src/libcore/fmt/mod.rs:1087
  50: core::fmt::write
             at src/libcore/fmt/mod.rs:1062
  51: core::fmt::Write::write_fmt
             at ./src/libcore/fmt/mod.rs:195
  52: alloc::fmt::format
             at src/liballoc/fmt.rs:571
  53: rustc_mir::util::pretty::write_basic_block
             at src/librustc_mir/util/pretty.rs:303
  54: rustc_mir::util::pretty::write_mir_fn
             at src/librustc_mir/util/pretty.rs:272
  55: rustc_mir::util::pretty::write_mir_pretty
             at src/librustc_mir/util/pretty.rs:248
  56: rustc_mir::transform::dump_mir::emit_mir
             at src/librustc_mir/transform/dump_mir.rs:65
  57: rustc_interface::passes::start_codegen
             at src/librustc_interface/passes.rs:973
  58: rustc_interface::queries::Queries::ongoing_codegen::{{closure}}::{{closure}}
             at src/librustc_interface/queries.rs:280
  59: rustc_interface::passes::QueryContext::enter::{{closure}}
             at src/librustc_interface/passes.rs:696
  60: rustc::ty::context::tls::enter_global::{{closure}}
             at ./src/librustc/ty/context.rs:1743
  61: rustc::ty::context::tls::enter_context::{{closure}}
             at ./src/librustc/ty/context.rs:1720
  62: rustc::ty::context::tls::set_tlv
             at ./src/librustc/ty/context.rs:1704
  63: rustc::ty::context::tls::enter_context
             at ./src/librustc/ty/context.rs:1720
  64: rustc::ty::context::tls::enter_global
             at ./src/librustc/ty/context.rs:1743
  65: rustc_interface::passes::QueryContext::enter
             at src/librustc_interface/passes.rs:696
  66: rustc_interface::queries::Queries::ongoing_codegen::{{closure}}
             at src/librustc_interface/queries.rs:274
  67: rustc_interface::queries::Query<T>::compute
             at src/librustc_interface/queries.rs:33
  68: rustc_interface::queries::Queries::ongoing_codegen
             at src/librustc_interface/queries.rs:272
  69: rustc_driver::run_compiler::{{closure}}::{{closure}}
             at src/librustc_driver/lib.rs:399
  70: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
             at ./src/librustc_interface/queries.rs:339
  71: rustc_driver::run_compiler::{{closure}}
             at src/librustc_driver/lib.rs:289
  72: rustc_interface::interface::run_compiler_in_existing_thread_pool
             at ./src/librustc_interface/interface.rs:199
  73: rustc_interface::interface::run_compiler::{{closure}}
             at ./src/librustc_interface/interface.rs:213
  74: rustc_interface::util::spawn_thread_pool::{{closure}}::{{closure}}::{{closure}}
             at ./src/librustc_interface/util.rs:155
  75: scoped_tls::ScopedKey<T>::set
             at /home/r/.cargo/registry/src/github.com-1ecc6299db9ec823/scoped-tls-1.0.0/src/lib.rs:137
  76: rustc_interface::util::spawn_thread_pool::{{closure}}::{{closure}}
             at ./src/librustc_interface/util.rs:151
  77: scoped_tls::ScopedKey<T>::set
             at /home/r/.cargo/registry/src/github.com-1ecc6299db9ec823/scoped-tls-1.0.0/src/lib.rs:137
  78: syntax::attr::with_globals::{{closure}}
             at ./src/libsyntax/attr/mod.rs:44
  79: scoped_tls::ScopedKey<T>::set
             at /home/r/.cargo/registry/src/github.com-1ecc6299db9ec823/scoped-tls-1.0.0/src/lib.rs:137
  80: syntax::attr::with_globals
             at ./src/libsyntax/attr/mod.rs:44
  81: rustc_interface::util::spawn_thread_pool::{{closure}}
             at ./src/librustc_interface/util.rs:150
  82: rustc_interface::util::scoped_thread::{{closure}}
             at ./src/librustc_interface/util.rs:125

@oli-obk Looks like the unwrap_memory here is wrong.

@RalfJung RalfJung changed the title Can't debug format a mir stmt in DefId(0:6927 ~ core[c569]::str[0]::utf8_char_width[0]) ICE in --emit mir: expected allocation ID to point to memory Feb 28, 2020
@JohnTitor JohnTitor added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label May 27, 2020
@JohnTitor
Copy link
Member

Triage: I think that ICE is fixed by #72424, no longer occurs with the latest nightly. Marking as E-needs-test.

JohnTitor added a commit to JohnTitor/rust that referenced this issue May 28, 2020
bors added a commit to rust-lang-ci/rust that referenced this issue May 29, 2020
Rollup of 12 pull requests

Successful merges:

 - rust-lang#72239 (Implement PartialOrd and Ord for SocketAddr*)
 - rust-lang#72466 (Stabilize str_strip feature)
 - rust-lang#72605 (Add working example for E0617 explanation)
 - rust-lang#72636 (Cleanup `Resolver::<clone|into>_outputs` methods)
 - rust-lang#72645 (Add myself to .mailmap)
 - rust-lang#72667 (expand unaligned_references test)
 - rust-lang#72670 (Fix incorrect comment in generator test)
 - rust-lang#72674 (Clippy should always build)
 - rust-lang#72682 (Add test for rust-lang#66930)
 - rust-lang#72695 (update data layout for illumos x86)
 - rust-lang#72697 (Remove rustc-ux-guidelines)
 - rust-lang#72702 (rustc_lint: Remove `unused_crate_dependencies` from the `unused` group)

Failed merges:

r? @ghost
@bors bors closed this as completed in 71512e4 May 29, 2020
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 (including `-Z unpretty`) C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. 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.

7 participants