Skip to content

Commit

Permalink
Fix mir-cfg dumps
Browse files Browse the repository at this point in the history
Fixes #81918
Fixes #82326 (duplicate)
Fixes #82325
  • Loading branch information
osa1 committed Feb 22, 2021
1 parent 8a9f786 commit 2145a87
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
23 changes: 18 additions & 5 deletions compiler/rustc_mir/src/util/graphviz.rs
Expand Up @@ -2,7 +2,7 @@ use gsgdt::GraphvizSettings;
use rustc_graphviz as dot;
use rustc_hir::def_id::DefId;
use rustc_middle::mir::*;
use rustc_middle::ty::TyCtxt;
use rustc_middle::ty::{self, TyCtxt};
use std::fmt::Debug;
use std::io::{self, Write};

Expand All @@ -16,14 +16,27 @@ where
{
let def_ids = dump_mir_def_ids(tcx, single);

let use_subgraphs = def_ids.len() > 1;
let mirs =
def_ids
.iter()
.flat_map(|def_id| {
if tcx.is_const_fn_raw(*def_id) {
vec![tcx.optimized_mir(*def_id), tcx.mir_for_ctfe(*def_id)]
} else {
vec![tcx.instance_mir(ty::InstanceDef::Item(ty::WithOptConstParam::unknown(
*def_id,
)))]
}
})
.collect::<Vec<_>>();

let use_subgraphs = mirs.len() > 1;
if use_subgraphs {
writeln!(w, "digraph __crate__ {{")?;
}

for def_id in def_ids {
let body = &tcx.optimized_mir(def_id);
write_mir_fn_graphviz(tcx, body, use_subgraphs, w)?;
for mir in mirs {
write_mir_fn_graphviz(tcx, mir, use_subgraphs, w)?;
}

if use_subgraphs {
Expand Down
11 changes: 11 additions & 0 deletions src/test/ui/issues/issue-81918.rs
@@ -0,0 +1,11 @@
// check-pass
// dont-check-compiler-stdout
// compile-flags: -Z unpretty=mir-cfg

// This checks that unpretty=mir-cfg does not panic. See #81918.

const TAG: &'static str = "ABCD";

fn main() {
if TAG == "" {}
}

0 comments on commit 2145a87

Please sign in to comment.