- Notifications
You must be signed in to change notification settings - Fork 13.9k
Turn moves into copies after copy propagation #147804
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
Open
tmiasko wants to merge 1 commit into rust-lang:master Choose a base branch from tmiasko:move-copy
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
37 changes: 0 additions & 37 deletions 37 tests/mir-opt/copy-prop/move_arg.f.CopyProp.panic-abort.diff
This file was deleted.
Oops, something went wrong.
37 changes: 0 additions & 37 deletions 37 tests/mir-opt/copy-prop/move_arg.f.CopyProp.panic-unwind.diff
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,46 @@ | ||
// skip-filecheck | ||
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY | ||
// Test that we do not move multiple times from the same local. | ||
//@ test-mir-pass: CopyProp | ||
//@ compile-flags: --crate-type=lib -Cpanic=abort | ||
#![feature(custom_mir, core_intrinsics)] | ||
use core::intrinsics::mir::*; | ||
use core::mem::MaybeUninit; | ||
extern crate core; | ||
| ||
// EMIT_MIR move_arg.f.CopyProp.diff | ||
pub fn f<T: Copy>(a: T) { | ||
let b = a; | ||
g(a, b); | ||
#[custom_mir(dialect = "runtime", phase = "initial")] | ||
pub fn moved_and_copied<T: Copy>(_1: T) { | ||
// CHECK-LABEL: fn moved_and_copied( | ||
// CHECK: _0 = f::<T>(copy _1, copy _1) | ||
mir! { | ||
{ | ||
let _2 = _1; | ||
Call(RET = f(Move(_1), Move(_2)), ReturnTo(bb1), UnwindUnreachable()) | ||
} | ||
bb1 = { | ||
Return() | ||
} | ||
} | ||
} | ||
| ||
#[inline(never)] | ||
pub fn g<T: Copy>(_: T, _: T) {} | ||
| ||
fn main() { | ||
f(5) | ||
#[custom_mir(dialect = "runtime", phase = "initial")] | ||
pub fn moved_twice<T: Copy>(_1: MaybeUninit<T>) { | ||
// In a future we would like to propagate moves instead of copies here. The resulting program | ||
// would have an undefined behavior due to overlap in a call terminator, so we need to change | ||
// operational semantics to explain why the original program has undefined behavior. | ||
// https://github.com/rust-lang/unsafe-code-guidelines/issues/556 | ||
// | ||
// CHECK-LABEL: fn moved_twice( | ||
// CHECK: _0 = f::<MaybeUninit<T>>(copy _1, copy _1) | ||
mir! { | ||
{ | ||
let _2 = Move(_1); | ||
let _3 = Move(_1); | ||
Call(RET = f(Move(_2), Move(_3)), ReturnTo(bb1), UnwindUnreachable()) | ||
} | ||
bb1 = { | ||
Return() | ||
} | ||
} | ||
} | ||
| ||
#[inline(never)] | ||
pub fn f<T: Copy>(_: T, _: T) {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.