Fix cycle error only occurring with -Zdump-mir
This commit is contained in:
parent
88ab2d8acb
commit
15c01eb22c
4 changed files with 37 additions and 16 deletions
|
@ -1555,16 +1555,22 @@ pub fn write_allocations<'tcx>(
|
||||||
write!(w, " (vtable: impl {dyn_ty} for {ty})")?
|
write!(w, " (vtable: impl {dyn_ty} for {ty})")?
|
||||||
}
|
}
|
||||||
Some(GlobalAlloc::Static(did)) if !tcx.is_foreign_item(did) => {
|
Some(GlobalAlloc::Static(did)) if !tcx.is_foreign_item(did) => {
|
||||||
match tcx.eval_static_initializer(did) {
|
write!(w, " (static: {}", tcx.def_path_str(did))?;
|
||||||
Ok(alloc) => {
|
if body.phase <= MirPhase::Runtime(RuntimePhase::PostCleanup)
|
||||||
write!(w, " (static: {}, ", tcx.def_path_str(did))?;
|
&& tcx.hir().body_const_context(body.source.def_id()).is_some()
|
||||||
write_allocation_track_relocs(w, alloc)?;
|
{
|
||||||
|
// Statics may be cyclic and evaluating them too early
|
||||||
|
// in the MIR pipeline may cause cycle errors even though
|
||||||
|
// normal compilation is fine.
|
||||||
|
write!(w, ")")?;
|
||||||
|
} else {
|
||||||
|
match tcx.eval_static_initializer(did) {
|
||||||
|
Ok(alloc) => {
|
||||||
|
write!(w, ", ")?;
|
||||||
|
write_allocation_track_relocs(w, alloc)?;
|
||||||
|
}
|
||||||
|
Err(_) => write!(w, ", error during initializer evaluation)")?,
|
||||||
}
|
}
|
||||||
Err(_) => write!(
|
|
||||||
w,
|
|
||||||
" (static: {}, error during initializer evaluation)",
|
|
||||||
tcx.def_path_str(did)
|
|
||||||
)?,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(GlobalAlloc::Static(did)) => {
|
Some(GlobalAlloc::Static(did)) => {
|
||||||
|
|
19
tests/mir-opt/building/dump_mir_cycle.rs
Normal file
19
tests/mir-opt/building/dump_mir_cycle.rs
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct Thing {
|
||||||
|
pub next: &'static Thing,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub static THING: Thing = Thing { next: &THING };
|
||||||
|
// CHECK: alloc{{.+}} (static: THING)
|
||||||
|
|
||||||
|
const fn thing() -> &'static Thing {
|
||||||
|
&MUTUALLY_RECURSIVE
|
||||||
|
}
|
||||||
|
|
||||||
|
pub static MUTUALLY_RECURSIVE: Thing = Thing { next: thing() };
|
||||||
|
// CHECK: alloc{{.+}} (static: MUTUALLY_RECURSIVE)
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
// Generate optimized MIR for the const fn, too.
|
||||||
|
thing();
|
||||||
|
}
|
|
@ -15,6 +15,4 @@ const BAR::promoted[0]: &[&i32; 1] = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ALLOC0 (static: Y, size: 4, align: 4) {
|
ALLOC0 (static: Y)
|
||||||
2a 00 00 00 │ *...
|
|
||||||
}
|
|
||||||
|
|
|
@ -38,9 +38,7 @@
|
||||||
bb2 (cleanup): {
|
bb2 (cleanup): {
|
||||||
resume;
|
resume;
|
||||||
}
|
}
|
||||||
- }
|
|
||||||
-
|
|
||||||
- ALLOC0 (static: Y, size: 4, align: 4) {
|
|
||||||
- 2a 00 00 00 │ *...
|
|
||||||
}
|
}
|
||||||
|
-
|
||||||
|
- ALLOC0 (static: Y)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue