Skip to content

Commit aa1405f

Browse files
authored
Rollup merge of #82362 - osa1:issue81918, r=oli-obk
Fix mir-cfg dumps Fixes #81918 Fixes #82326 (duplicate) Fixes #82325 --- r? ``@oli-obk``
2 parents 619e47b + 2145a87 commit aa1405f

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

compiler/rustc_mir/src/util/graphviz.rs

+18-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use gsgdt::GraphvizSettings;
22
use rustc_graphviz as dot;
33
use rustc_hir::def_id::DefId;
44
use rustc_middle::mir::*;
5-
use rustc_middle::ty::TyCtxt;
5+
use rustc_middle::ty::{self, TyCtxt};
66
use std::fmt::Debug;
77
use std::io::{self, Write};
88

@@ -16,14 +16,27 @@ where
1616
{
1717
let def_ids = dump_mir_def_ids(tcx, single);
1818

19-
let use_subgraphs = def_ids.len() > 1;
19+
let mirs =
20+
def_ids
21+
.iter()
22+
.flat_map(|def_id| {
23+
if tcx.is_const_fn_raw(*def_id) {
24+
vec![tcx.optimized_mir(*def_id), tcx.mir_for_ctfe(*def_id)]
25+
} else {
26+
vec![tcx.instance_mir(ty::InstanceDef::Item(ty::WithOptConstParam::unknown(
27+
*def_id,
28+
)))]
29+
}
30+
})
31+
.collect::<Vec<_>>();
32+
33+
let use_subgraphs = mirs.len() > 1;
2034
if use_subgraphs {
2135
writeln!(w, "digraph __crate__ {{")?;
2236
}
2337

24-
for def_id in def_ids {
25-
let body = &tcx.optimized_mir(def_id);
26-
write_mir_fn_graphviz(tcx, body, use_subgraphs, w)?;
38+
for mir in mirs {
39+
write_mir_fn_graphviz(tcx, mir, use_subgraphs, w)?;
2740
}
2841

2942
if use_subgraphs {

src/test/ui/issues/issue-81918.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// check-pass
2+
// dont-check-compiler-stdout
3+
// compile-flags: -Z unpretty=mir-cfg
4+
5+
// This checks that unpretty=mir-cfg does not panic. See #81918.
6+
7+
const TAG: &'static str = "ABCD";
8+
9+
fn main() {
10+
if TAG == "" {}
11+
}

0 commit comments

Comments
 (0)