Rollup merge of #82362 - osa1:issue81918, r=oli-obk

Fix mir-cfg dumps

Fixes #81918
Fixes #82326 (duplicate)
Fixes #82325

---

r? ``@oli-obk``
This commit is contained in:
Dylan DPC 2021-02-23 16:10:29 +01:00 committed by GitHub
commit aa1405fff7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 5 deletions

View File

@ -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};
@ -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 {

View File

@ -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 == "" {}
}