Only preserving derefs for trivial terminators like SwitchInt and Goto

This commit is contained in:
dianqk 2025-03-24 16:55:24 +08:00
parent ac7dd7a1b3
commit 4e05d858ad
No known key found for this signature in database

View file

@ -1779,8 +1779,14 @@ impl<'tcx> MutVisitor<'tcx> for VnState<'_, 'tcx> {
let opaque = self.new_opaque();
self.assign(local, opaque);
}
// Function calls maybe invalidate nested deref, and non-local assignments maybe invalidate deref.
// Currently, no distinction is made between these two cases.
}
// Function calls and ASM may invalidate (nested) derefs. We must handle them carefully.
// Currently, only preserving derefs for trivial terminators like SwitchInt and Goto.
let safe_to_preserve_derefs = matches!(
terminator.kind,
TerminatorKind::SwitchInt { .. } | TerminatorKind::Goto { .. }
);
if !safe_to_preserve_derefs {
self.invalidate_derefs();
}
self.super_terminator(terminator, location);