Skip to content

Fix change detection in CfgSimplifier::collapse_goto_chain #75076

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/librustc_mir/transform/simplify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,6 @@ impl<'a, 'tcx> CfgSimplifier<'a, 'tcx> {
}

self.basic_blocks[bb].terminator = Some(terminator);

changed |= inner_changed;
}

if !changed {
Expand Down Expand Up @@ -212,6 +210,7 @@ impl<'a, 'tcx> CfgSimplifier<'a, 'tcx> {
Terminator { kind: TerminatorKind::Goto { ref mut target }, .. } => target,
_ => unreachable!(),
};
*changed |= *target != last;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @ecstatic-morse We now have a test case for this!

*target = last;
debug!("collapsing goto chain from {:?} to {:?}", current, target);

Expand All @@ -223,7 +222,6 @@ impl<'a, 'tcx> CfgSimplifier<'a, 'tcx> {
self.pred_count[*target] += 1;
self.pred_count[current] -= 1;
}
*changed = true;
self.basic_blocks[current].terminator = Some(terminator);
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/test/ui/issues/issue-75704.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Caused an infinite loop during SimlifyCfg MIR transform previously.
//
// build-pass
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this really test this mir pass? don't you also need -Zmir-opt-level=2?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this test case no additional flags are necessary to reproduce the issue. Unlike the one from #75051 which also needed -Zmir-opt-level=2.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, superb! thanks


fn main() {
loop { continue; }
}