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})")?
|
||||
}
|
||||
Some(GlobalAlloc::Static(did)) if !tcx.is_foreign_item(did) => {
|
||||
match tcx.eval_static_initializer(did) {
|
||||
Ok(alloc) => {
|
||||
write!(w, " (static: {}, ", tcx.def_path_str(did))?;
|
||||
write_allocation_track_relocs(w, alloc)?;
|
||||
write!(w, " (static: {}", tcx.def_path_str(did))?;
|
||||
if body.phase <= MirPhase::Runtime(RuntimePhase::PostCleanup)
|
||||
&& tcx.hir().body_const_context(body.source.def_id()).is_some()
|
||||
{
|
||||
// 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)) => {
|
||||
|
|
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) {
|
||||
2a 00 00 00 │ *...
|
||||
}
|
||||
ALLOC0 (static: Y)
|
||||
|
|
|
@ -38,9 +38,7 @@
|
|||
bb2 (cleanup): {
|
||||
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