2023-06-08 07:18:34 +00:00
|
|
|
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
|
2020-05-24 19:37:09 +00:00
|
|
|
//! Tests that assignment in both branches of an `if` are eliminated.
|
2024-04-20 11:19:34 +00:00
|
|
|
//@ test-mir-pass: DestinationPropagation
|
2020-05-24 19:37:09 +00:00
|
|
|
fn val() -> i32 {
|
|
|
|
1
|
|
|
|
}
|
|
|
|
|
|
|
|
fn cond() -> bool {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
|
2022-04-24 21:34:24 +00:00
|
|
|
// EMIT_MIR branch.foo.DestinationPropagation.diff
|
|
|
|
fn foo() -> i32 {
|
2024-04-14 09:35:01 +00:00
|
|
|
// CHECK-LABEL: fn foo(
|
|
|
|
// CHECK: debug y => [[y:_.*]];
|
|
|
|
// CHECK: [[y]] = val()
|
|
|
|
// CHECK-NOT: [[y]] = {{_.*}};
|
2020-05-24 19:37:09 +00:00
|
|
|
let x = val();
|
|
|
|
|
|
|
|
let y = if cond() {
|
|
|
|
x
|
|
|
|
} else {
|
|
|
|
val();
|
|
|
|
x
|
|
|
|
};
|
2022-04-24 21:34:24 +00:00
|
|
|
|
|
|
|
y
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
foo();
|
2020-05-24 19:37:09 +00:00
|
|
|
}
|