diff options
| author | Ralf Jung <post@ralfj.de> | 2023-09-04 15:32:07 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2023-09-04 18:27:34 +0200 |
| commit | 7093903ba7a71c1d30e817daa41a4328dc6a8db2 (patch) | |
| tree | 2a91001874a904549b6fbd6ecc6bba1dcab6b7b5 /compiler/rustc_mir_transform/src/lower_intrinsics.rs | |
| parent | a989e25f1b87949a886eab3da10324d14189fe95 (diff) | |
| download | rust-7093903ba7a71c1d30e817daa41a4328dc6a8db2.tar.gz rust-7093903ba7a71c1d30e817daa41a4328dc6a8db2.zip | |
read_via_copy: don't prematurely optimize away the read
Diffstat (limited to 'compiler/rustc_mir_transform/src/lower_intrinsics.rs')
| -rw-r--r-- | compiler/rustc_mir_transform/src/lower_intrinsics.rs | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/compiler/rustc_mir_transform/src/lower_intrinsics.rs b/compiler/rustc_mir_transform/src/lower_intrinsics.rs index fc36c6e4124..a8dc91ca439 100644 --- a/compiler/rustc_mir_transform/src/lower_intrinsics.rs +++ b/compiler/rustc_mir_transform/src/lower_intrinsics.rs @@ -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 => { |
