Skip to content

Commit

Permalink
Fix crash with -Zdump-mir-dataflow
Browse files Browse the repository at this point in the history
As of rust-lang#133155 `Formatter:new` uses `as_results_cursor` to create a
non-mutable results reference, and then later that is accessed via
`deref_mut` which results in a runtime abort. Changing to
`as_results_cursor_mut` fixes it.

Fixes rust-lang#133641.
  • Loading branch information
nnethercote committed Dec 2, 2024
1 parent 5e1440a commit d37ed10
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_mir_dataflow/src/framework/graphviz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ where
{
pub(crate) fn new(
body: &'mir Body<'tcx>,
results: &'mir Results<'tcx, A>,
results: &'mir mut Results<'tcx, A>,
style: OutputStyle,
) -> Self {
let reachable = mir::traversal::reachable_as_bitset(body);
Formatter { cursor: results.as_results_cursor(body).into(), style, reachable }
Formatter { cursor: results.as_results_cursor_mut(body).into(), style, reachable }
}

fn body(&self) -> &'mir Body<'tcx> {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_mir_dataflow/src/framework/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,10 @@ pub trait Analysis<'tcx> {
);
}

let results = Results { analysis: self, entry_sets };
let mut results = Results { analysis: self, entry_sets };

if tcx.sess.opts.unstable_opts.dump_mir_dataflow {
let res = write_graphviz_results(tcx, body, &results, pass_name);
let res = write_graphviz_results(tcx, body, &mut results, pass_name);
if let Err(e) = res {
error!("Failed to write graphviz dataflow results: {}", e);
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_dataflow/src/framework/results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ where
pub(super) fn write_graphviz_results<'tcx, A>(
tcx: TyCtxt<'tcx>,
body: &mir::Body<'tcx>,
results: &Results<'tcx, A>,
results: &mut Results<'tcx, A>,
pass_name: Option<&'static str>,
) -> std::io::Result<()>
where
Expand Down

0 comments on commit d37ed10

Please sign in to comment.