Skip to content

Commit 4e05d85

Browse files
committed
Only preserving derefs for trivial terminators like SwitchInt and Goto
1 parent ac7dd7a commit 4e05d85

File tree

1 file changed

+8
-2
lines changed
  • compiler/rustc_mir_transform/src

1 file changed

+8
-2
lines changed

Diff for: compiler/rustc_mir_transform/src/gvn.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -1779,8 +1779,14 @@ impl<'tcx> MutVisitor<'tcx> for VnState<'_, 'tcx> {
17791779
let opaque = self.new_opaque();
17801780
self.assign(local, opaque);
17811781
}
1782-
// Function calls maybe invalidate nested deref, and non-local assignments maybe invalidate deref.
1783-
// Currently, no distinction is made between these two cases.
1782+
}
1783+
// Function calls and ASM may invalidate (nested) derefs. We must handle them carefully.
1784+
// Currently, only preserving derefs for trivial terminators like SwitchInt and Goto.
1785+
let safe_to_preserve_derefs = matches!(
1786+
terminator.kind,
1787+
TerminatorKind::SwitchInt { .. } | TerminatorKind::Goto { .. }
1788+
);
1789+
if !safe_to_preserve_derefs {
17841790
self.invalidate_derefs();
17851791
}
17861792
self.super_terminator(terminator, location);

0 commit comments

Comments
 (0)