1
Fork 0

read_via_copy: don't prematurely optimize away the read

This commit is contained in:
Ralf Jung 2023-09-04 15:32:07 +02:00
parent a989e25f1b
commit 7093903ba7
5 changed files with 39 additions and 16 deletions

View file

@ -176,23 +176,22 @@ impl<'tcx> MirPass<'tcx> for LowerIntrinsics {
} else {
span_bug!(terminator.source_info.span, "Only passing a local is supported");
};
// Add new statement at the end of the block that does the read, and patch
// up the terminator.
block.statements.push(Statement {
source_info: terminator.source_info,
kind: StatementKind::Assign(Box::new((
*destination,
Rvalue::Use(Operand::Copy(derefed_place)),
))),
});
terminator.kind = match *target {
None => {
// No target means this read something uninhabited,
// so it must be unreachable, and we don't need to
// preserve the assignment either.
// so it must be unreachable.
TerminatorKind::Unreachable
}
Some(target) => {
block.statements.push(Statement {
source_info: terminator.source_info,
kind: StatementKind::Assign(Box::new((
*destination,
Rvalue::Use(Operand::Copy(derefed_place)),
))),
});
TerminatorKind::Goto { target }
}
Some(target) => TerminatorKind::Goto { target },
}
}
sym::write_via_move => {