Skip to content

error: internal compiler error: src/librustc/mir/interpret/mod.rs:480: expected allocation ID 349 to point to memory #67558

Closed
@bjorn3

Description

@bjorn3
Member

This is while debug printing all mir statements of libcore.

error: internal compiler error: src/librustc/mir/interpret/mod.rs:480: expected allocation ID 349 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::sty::Const as rustc::ty::print::Print<P>>::print
  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}}
  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
  47: rustc_codegen_cranelift::driver::codegen_mono_items::{{closure}}
  48: rustc_codegen_cranelift::driver::time
  49: rustc_codegen_cranelift::driver::codegen_mono_items
  50: rustc_codegen_cranelift::driver::codegen_cgus
  51: rustc_codegen_cranelift::driver::run_aot
  52: rustc_codegen_cranelift::driver::codegen_crate
  53: <rustc_codegen_cranelift::CraneliftCodegenBackend as rustc_codegen_utils::codegen_backend::CodegenBackend>::codegen_crate
  54: rustc_interface::passes::start_codegen::{{closure}}
  55: rustc_interface::passes::start_codegen
  56: rustc::ty::context::tls::enter_global
  57: rustc_interface::queries::Queries::ongoing_codegen
  58: rustc_interface::interface::run_compiler_in_existing_thread_pool
  59: std::thread::local::LocalKey<T>::with
  60: scoped_tls::ScopedKey<T>::set
  61: 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.42.0-nightly (01a46509a 2019-12-20) 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

Activity

bjorn3

bjorn3 commented on Dec 23, 2019

@bjorn3
MemberAuthor

@rustbot modify labels: +A-mir +C-bug +requires-nightly

added
A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html
C-bugCategory: This is a bug.
requires-nightlyThis issue requires a nightly compiler in some way.
on Dec 23, 2019
added
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Dec 23, 2019
matthiaskrgr

matthiaskrgr commented on Dec 29, 2019

@matthiaskrgr
Member

This also reproduces on rustc src/test/ui/issues/issue-25145.rs --emit mir.

bjorn3

bjorn3 commented on Feb 22, 2020

@bjorn3
MemberAuthor

The pretty_print_const_value incorrectly assumes at several places that the allocation kind is always what the type should contain. It for example assumes that an fn() value always points to a function, and &[u8] always points to raw bytes. It also ignores relocations at several places.

fn pretty_print_const_value(
mut self,
ct: ConstValue<'tcx>,
ty: Ty<'tcx>,
print_ty: bool,
) -> Result<Self::Const, Self::Error> {
define_scoped_cx!(self);
if self.tcx().sess.verbose() {
p!(write("ConstValue({:?}: {:?})", ct, ty));
return Ok(self);
}
let u8 = self.tcx().types.u8;
match (ct, &ty.kind) {
(ConstValue::Scalar(Scalar::Raw { data, .. }), ty::Bool) => {
p!(write("{}", if data == 0 { "false" } else { "true" }))
}
(ConstValue::Scalar(Scalar::Raw { data, .. }), ty::Float(ast::FloatTy::F32)) => {
p!(write("{}f32", Single::from_bits(data)))
}
(ConstValue::Scalar(Scalar::Raw { data, .. }), ty::Float(ast::FloatTy::F64)) => {
p!(write("{}f64", Double::from_bits(data)))
}
(ConstValue::Scalar(Scalar::Raw { data, .. }), ty::Uint(ui)) => {
let bit_size = Integer::from_attr(&self.tcx(), UnsignedInt(*ui)).size();
let max = truncate(u128::max_value(), bit_size);
let ui_str = ui.name_str();
if data == max {
p!(write("std::{}::MAX", ui_str))
} else {
p!(write("{}{}", data, ui_str))
};
}
(ConstValue::Scalar(Scalar::Raw { data, .. }), ty::Int(i)) => {
let bit_size = Integer::from_attr(&self.tcx(), SignedInt(*i)).size().bits() as u128;
let min = 1u128 << (bit_size - 1);
let max = min - 1;
let ty = self.tcx().lift(&ty).unwrap();
let size = self.tcx().layout_of(ty::ParamEnv::empty().and(ty)).unwrap().size;
let i_str = i.name_str();
match data {
d if d == min => p!(write("std::{}::MIN", i_str)),
d if d == max => p!(write("std::{}::MAX", i_str)),
_ => p!(write("{}{}", sign_extend(data, size) as i128, i_str)),
}
}
(ConstValue::Scalar(Scalar::Raw { data, .. }), ty::Char) => {
p!(write("{:?}", ::std::char::from_u32(data as u32).unwrap()))
}
(ConstValue::Scalar(_), ty::RawPtr(_)) => p!(write("{{pointer}}")),
(ConstValue::Scalar(Scalar::Ptr(ptr)), ty::FnPtr(_)) => {
let instance = {
let alloc_map = self.tcx().alloc_map.lock();
alloc_map.unwrap_fn(ptr.alloc_id)
};
p!(print_value_path(instance.def_id(), instance.substs));
}
_ => {
let printed = if let ty::Ref(_, ref_ty, _) = ty.kind {
let byte_str = match (ct, &ref_ty.kind) {
(ConstValue::Scalar(Scalar::Ptr(ptr)), ty::Array(t, n)) if *t == u8 => {
let n = n.eval_usize(self.tcx(), ty::ParamEnv::empty());
Some(
self.tcx()
.alloc_map
.lock()
.unwrap_memory(ptr.alloc_id)
.get_bytes(&self.tcx(), ptr, Size::from_bytes(n))
.unwrap(),
)
}
(ConstValue::Slice { data, start, end }, ty::Slice(t)) if *t == u8 => {
// The `inspect` here is okay since we checked the bounds, and there are
// no relocations (we have an active slice reference here). We don't use
// this result to affect interpreter execution.
Some(data.inspect_with_undef_and_ptr_outside_interpreter(start..end))
}
_ => None,
};
if let Some(byte_str) = byte_str {
p!(write("b\""));
for &c in byte_str {
for e in std::ascii::escape_default(c) {
self.write_char(e as char)?;
}
}
p!(write("\""));
true
} else if let (ConstValue::Slice { data, start, end }, ty::Str) =
(ct, &ref_ty.kind)
{
// The `inspect` here is okay since we checked the bounds, and there are no
// relocations (we have an active `str` reference here). We don't use this
// result to affect interpreter execution.
let slice = data.inspect_with_undef_and_ptr_outside_interpreter(start..end);
let s = ::std::str::from_utf8(slice).expect("non utf8 str from miri");
p!(write("{:?}", s));
true
} else {
false
}
} else {
false
};
if !printed {
// fallback
p!(write("{:?}", ct));
if print_ty {
p!(write(": "), print(ty));
}
}
}
};
Ok(self)
}
}

added
I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
on Mar 8, 2020
JohnTitor

JohnTitor commented on May 27, 2020

@JohnTitor
Member

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

added
E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.
on May 27, 2020
added a commit that references this issue on May 29, 2020

Rollup merge of rust-lang#72682 - JohnTitor:mir-tests, r=RalfJung

71512e4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlC-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @matthiaskrgr@Centril@jonas-schievink@bjorn3@JohnTitor

      Issue actions

        error: internal compiler error: src/librustc/mir/interpret/mod.rs:480: expected allocation ID 349 to point to memory · Issue #67558 · rust-lang/rust