simplify-locals: Remove unused assignments regardless of rvalue kind
This commit is contained in:
parent
52d3782685
commit
4c3e06a0ba
13 changed files with 36 additions and 69 deletions
|
@ -439,31 +439,7 @@ impl Visitor<'_> for UsedLocals {
|
||||||
StatementKind::StorageLive(_local) | StatementKind::StorageDead(_local) => {}
|
StatementKind::StorageLive(_local) | StatementKind::StorageDead(_local) => {}
|
||||||
|
|
||||||
StatementKind::Assign(box (ref place, ref rvalue)) => {
|
StatementKind::Assign(box (ref place, ref rvalue)) => {
|
||||||
let can_skip = match rvalue {
|
|
||||||
Rvalue::Use(_)
|
|
||||||
| Rvalue::Discriminant(_)
|
|
||||||
| Rvalue::BinaryOp(_, _, _)
|
|
||||||
| Rvalue::CheckedBinaryOp(_, _, _)
|
|
||||||
| Rvalue::Repeat(_, _)
|
|
||||||
| Rvalue::AddressOf(_, _)
|
|
||||||
| Rvalue::Len(_)
|
|
||||||
| Rvalue::UnaryOp(_, _)
|
|
||||||
| Rvalue::Aggregate(_, _) => true,
|
|
||||||
|
|
||||||
Rvalue::Ref(..)
|
|
||||||
| Rvalue::ThreadLocalRef(..)
|
|
||||||
| Rvalue::Cast(..)
|
|
||||||
| Rvalue::NullaryOp(..) => false,
|
|
||||||
};
|
|
||||||
if can_skip {
|
|
||||||
self.visit_lhs(place, location);
|
self.visit_lhs(place, location);
|
||||||
} else {
|
|
||||||
self.visit_place(
|
|
||||||
place,
|
|
||||||
PlaceContext::MutatingUse(MutatingUseContext::Store),
|
|
||||||
location,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
self.visit_rvalue(rvalue, location);
|
self.visit_rvalue(rvalue, location);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
// ignore-tidy-linelength
|
// ignore-tidy-linelength
|
||||||
// compile-flags:-Zprint-mono-items=eager
|
// compile-flags:-Zprint-mono-items=eager -Zinline-in-all-cgus -Zmir-opt-level=0
|
||||||
// compile-flags:-Zinline-in-all-cgus
|
|
||||||
|
|
||||||
#![deny(dead_code)]
|
#![deny(dead_code)]
|
||||||
#![feature(start)]
|
#![feature(start)]
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// compile-flags: -O -C no-prepopulate-passes
|
// compile-flags: -O -C no-prepopulate-passes -Zmir-opt-level=0
|
||||||
|
|
||||||
#![crate_type = "lib"]
|
#![crate_type = "lib"]
|
||||||
|
|
||||||
|
@ -18,10 +18,10 @@ pub fn test() {
|
||||||
// CHECK: [[S_b:%[0-9]+]] = bitcast { i32, i32 }** %b to i8*
|
// CHECK: [[S_b:%[0-9]+]] = bitcast { i32, i32 }** %b to i8*
|
||||||
// CHECK: call void @llvm.lifetime.start{{.*}}(i{{[0-9 ]+}}, i8* [[S_b]])
|
// CHECK: call void @llvm.lifetime.start{{.*}}(i{{[0-9 ]+}}, i8* [[S_b]])
|
||||||
|
|
||||||
// CHECK: [[S__4:%[0-9]+]] = bitcast { i32, i32 }* %_4 to i8*
|
// CHECK: [[S__4:%[0-9]+]] = bitcast { i32, i32 }* %_5 to i8*
|
||||||
// CHECK: call void @llvm.lifetime.start{{.*}}(i{{[0-9 ]+}}, i8* [[S__4]])
|
// CHECK: call void @llvm.lifetime.start{{.*}}(i{{[0-9 ]+}}, i8* [[S__4]])
|
||||||
|
|
||||||
// CHECK: [[E__4:%[0-9]+]] = bitcast { i32, i32 }* %_4 to i8*
|
// CHECK: [[E__4:%[0-9]+]] = bitcast { i32, i32 }* %_5 to i8*
|
||||||
// CHECK: call void @llvm.lifetime.end{{.*}}(i{{[0-9 ]+}}, i8* [[E__4]])
|
// CHECK: call void @llvm.lifetime.end{{.*}}(i{{[0-9 ]+}}, i8* [[E__4]])
|
||||||
|
|
||||||
// CHECK: [[E_b:%[0-9]+]] = bitcast { i32, i32 }** %b to i8*
|
// CHECK: [[E_b:%[0-9]+]] = bitcast { i32, i32 }** %b to i8*
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// compile-flags: -C no-prepopulate-passes
|
// compile-flags: -C no-prepopulate-passes -Zmir-opt-level=0
|
||||||
|
|
||||||
#![crate_type = "lib"]
|
#![crate_type = "lib"]
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// compile-flags: -C no-prepopulate-passes
|
// compile-flags: -C no-prepopulate-passes -Zmir-opt-level=0
|
||||||
|
|
||||||
#![crate_type = "lib"]
|
#![crate_type = "lib"]
|
||||||
#![feature(naked_functions)]
|
#![feature(naked_functions)]
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// compile-flags: -C no-prepopulate-passes
|
// compile-flags: -C no-prepopulate-passes -Zmir-opt-level=0
|
||||||
|
|
||||||
#![crate_type = "lib"]
|
#![crate_type = "lib"]
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
// build-pass (FIXME(62277): could be check-pass?)
|
// build-pass (FIXME(62277): could be check-pass?)
|
||||||
// revisions: cfail1 cfail2 cfail3
|
// revisions: cfail1 cfail2 cfail3
|
||||||
// compile-flags: -Z query-dep-graph -Zincremental-ignore-spans
|
// compile-flags: -Z query-dep-graph -Zincremental-ignore-spans -Zmir-opt-level=0
|
||||||
|
|
||||||
#![allow(warnings)]
|
#![allow(warnings)]
|
||||||
#![feature(rustc_attrs)]
|
#![feature(rustc_attrs)]
|
||||||
|
@ -53,7 +53,7 @@ pub fn change_parameter_pattern() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(cfail1))]
|
#[cfg(not(cfail1))]
|
||||||
#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, typeck")]
|
#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, typeck, optimized_mir")]
|
||||||
#[rustc_clean(cfg="cfail3")]
|
#[rustc_clean(cfg="cfail3")]
|
||||||
pub fn change_parameter_pattern() {
|
pub fn change_parameter_pattern() {
|
||||||
let _ = |(x,): (u32,)| x;
|
let _ = |(x,): (u32,)| x;
|
||||||
|
|
|
@ -4,8 +4,8 @@
|
||||||
fn c() -> () {
|
fn c() -> () {
|
||||||
let mut _0: (); // return place in scope 0 at $DIR/simplify-locals.rs:13:8: 13:8
|
let mut _0: (); // return place in scope 0 at $DIR/simplify-locals.rs:13:8: 13:8
|
||||||
let _1: [u8; 10]; // in scope 0 at $DIR/simplify-locals.rs:14:9: 14:14
|
let _1: [u8; 10]; // in scope 0 at $DIR/simplify-locals.rs:14:9: 14:14
|
||||||
let mut _2: &[u8]; // in scope 0 at $DIR/simplify-locals.rs:16:20: 16:26
|
- let mut _2: &[u8]; // in scope 0 at $DIR/simplify-locals.rs:16:20: 16:26
|
||||||
let mut _3: &[u8; 10]; // in scope 0 at $DIR/simplify-locals.rs:16:20: 16:26
|
- let mut _3: &[u8; 10]; // in scope 0 at $DIR/simplify-locals.rs:16:20: 16:26
|
||||||
- let _4: &[u8; 10]; // in scope 0 at $DIR/simplify-locals.rs:16:20: 16:26
|
- let _4: &[u8; 10]; // in scope 0 at $DIR/simplify-locals.rs:16:20: 16:26
|
||||||
scope 1 {
|
scope 1 {
|
||||||
debug bytes => _1; // in scope 1 at $DIR/simplify-locals.rs:14:9: 14:14
|
debug bytes => _1; // in scope 1 at $DIR/simplify-locals.rs:14:9: 14:14
|
||||||
|
@ -16,10 +16,10 @@
|
||||||
bb0: {
|
bb0: {
|
||||||
StorageLive(_1); // scope 0 at $DIR/simplify-locals.rs:14:9: 14:14
|
StorageLive(_1); // scope 0 at $DIR/simplify-locals.rs:14:9: 14:14
|
||||||
_1 = [const 0_u8; 10]; // scope 0 at $DIR/simplify-locals.rs:14:17: 14:26
|
_1 = [const 0_u8; 10]; // scope 0 at $DIR/simplify-locals.rs:14:17: 14:26
|
||||||
StorageLive(_2); // scope 1 at $DIR/simplify-locals.rs:16:20: 16:26
|
- StorageLive(_2); // scope 1 at $DIR/simplify-locals.rs:16:20: 16:26
|
||||||
_3 = &_1; // scope 1 at $DIR/simplify-locals.rs:16:20: 16:26
|
- _3 = &_1; // scope 1 at $DIR/simplify-locals.rs:16:20: 16:26
|
||||||
_2 = move _3 as &[u8] (Pointer(Unsize)); // scope 1 at $DIR/simplify-locals.rs:16:20: 16:26
|
- _2 = move _3 as &[u8] (Pointer(Unsize)); // scope 1 at $DIR/simplify-locals.rs:16:20: 16:26
|
||||||
StorageDead(_2); // scope 1 at $DIR/simplify-locals.rs:16:26: 16:27
|
- StorageDead(_2); // scope 1 at $DIR/simplify-locals.rs:16:26: 16:27
|
||||||
_0 = const (); // scope 0 at $DIR/simplify-locals.rs:13:8: 17:2
|
_0 = const (); // scope 0 at $DIR/simplify-locals.rs:13:8: 17:2
|
||||||
StorageDead(_1); // scope 0 at $DIR/simplify-locals.rs:17:1: 17:2
|
StorageDead(_1); // scope 0 at $DIR/simplify-locals.rs:17:1: 17:2
|
||||||
return; // scope 0 at $DIR/simplify-locals.rs:17:2: 17:2
|
return; // scope 0 at $DIR/simplify-locals.rs:17:2: 17:2
|
||||||
|
|
|
@ -4,8 +4,8 @@
|
||||||
fn r() -> () {
|
fn r() -> () {
|
||||||
let mut _0: (); // return place in scope 0 at $DIR/simplify-locals.rs:32:8: 32:8
|
let mut _0: (); // return place in scope 0 at $DIR/simplify-locals.rs:32:8: 32:8
|
||||||
let mut _1: i32; // in scope 0 at $DIR/simplify-locals.rs:33:9: 33:14
|
let mut _1: i32; // in scope 0 at $DIR/simplify-locals.rs:33:9: 33:14
|
||||||
let mut _2: &i32; // in scope 0 at $DIR/simplify-locals.rs:35:13: 35:15
|
- let mut _2: &i32; // in scope 0 at $DIR/simplify-locals.rs:35:13: 35:15
|
||||||
let mut _3: &mut i32; // in scope 0 at $DIR/simplify-locals.rs:36:13: 36:19
|
- let mut _3: &mut i32; // in scope 0 at $DIR/simplify-locals.rs:36:13: 36:19
|
||||||
scope 1 {
|
scope 1 {
|
||||||
debug a => _1; // in scope 1 at $DIR/simplify-locals.rs:33:9: 33:14
|
debug a => _1; // in scope 1 at $DIR/simplify-locals.rs:33:9: 33:14
|
||||||
scope 2 {
|
scope 2 {
|
||||||
|
@ -17,12 +17,12 @@
|
||||||
bb0: {
|
bb0: {
|
||||||
StorageLive(_1); // scope 0 at $DIR/simplify-locals.rs:33:9: 33:14
|
StorageLive(_1); // scope 0 at $DIR/simplify-locals.rs:33:9: 33:14
|
||||||
_1 = const 1_i32; // scope 0 at $DIR/simplify-locals.rs:33:17: 33:18
|
_1 = const 1_i32; // scope 0 at $DIR/simplify-locals.rs:33:17: 33:18
|
||||||
StorageLive(_2); // scope 1 at $DIR/simplify-locals.rs:35:13: 35:15
|
- StorageLive(_2); // scope 1 at $DIR/simplify-locals.rs:35:13: 35:15
|
||||||
_2 = &_1; // scope 1 at $DIR/simplify-locals.rs:35:13: 35:15
|
- _2 = &_1; // scope 1 at $DIR/simplify-locals.rs:35:13: 35:15
|
||||||
StorageDead(_2); // scope 1 at $DIR/simplify-locals.rs:35:15: 35:16
|
- StorageDead(_2); // scope 1 at $DIR/simplify-locals.rs:35:15: 35:16
|
||||||
StorageLive(_3); // scope 2 at $DIR/simplify-locals.rs:36:13: 36:19
|
- StorageLive(_3); // scope 2 at $DIR/simplify-locals.rs:36:13: 36:19
|
||||||
_3 = &mut _1; // scope 2 at $DIR/simplify-locals.rs:36:13: 36:19
|
- _3 = &mut _1; // scope 2 at $DIR/simplify-locals.rs:36:13: 36:19
|
||||||
StorageDead(_3); // scope 2 at $DIR/simplify-locals.rs:36:19: 36:20
|
- StorageDead(_3); // scope 2 at $DIR/simplify-locals.rs:36:19: 36:20
|
||||||
_0 = const (); // scope 0 at $DIR/simplify-locals.rs:32:8: 37:2
|
_0 = const (); // scope 0 at $DIR/simplify-locals.rs:32:8: 37:2
|
||||||
StorageDead(_1); // scope 0 at $DIR/simplify-locals.rs:37:1: 37:2
|
StorageDead(_1); // scope 0 at $DIR/simplify-locals.rs:37:1: 37:2
|
||||||
return; // scope 0 at $DIR/simplify-locals.rs:37:2: 37:2
|
return; // scope 0 at $DIR/simplify-locals.rs:37:2: 37:2
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
let mut _0: (); // return place in scope 0 at $DIR/simplify-locals.rs:42:9: 42:9
|
let mut _0: (); // return place in scope 0 at $DIR/simplify-locals.rs:42:9: 42:9
|
||||||
- let _1: u32; // in scope 0 at $DIR/simplify-locals.rs:44:14: 44:15
|
- let _1: u32; // in scope 0 at $DIR/simplify-locals.rs:44:14: 44:15
|
||||||
- let mut _2: *mut u32; // in scope 0 at $DIR/simplify-locals.rs:44:14: 44:15
|
- let mut _2: *mut u32; // in scope 0 at $DIR/simplify-locals.rs:44:14: 44:15
|
||||||
+ let mut _1: *mut u32; // in scope 0 at $DIR/simplify-locals.rs:44:14: 44:15
|
|
||||||
scope 1 {
|
scope 1 {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,9 +14,7 @@
|
||||||
- _2 = &/*tls*/ mut X; // scope 1 at $DIR/simplify-locals.rs:44:14: 44:15
|
- _2 = &/*tls*/ mut X; // scope 1 at $DIR/simplify-locals.rs:44:14: 44:15
|
||||||
- _1 = (*_2); // scope 1 at $DIR/simplify-locals.rs:44:14: 44:15
|
- _1 = (*_2); // scope 1 at $DIR/simplify-locals.rs:44:14: 44:15
|
||||||
- StorageDead(_2); // scope 0 at $DIR/simplify-locals.rs:44:17: 44:18
|
- StorageDead(_2); // scope 0 at $DIR/simplify-locals.rs:44:17: 44:18
|
||||||
+ StorageLive(_1); // scope 1 at $DIR/simplify-locals.rs:44:14: 44:15
|
- StorageDead(_1); // scope 0 at $DIR/simplify-locals.rs:44:17: 44:18
|
||||||
+ _1 = &/*tls*/ mut X; // scope 1 at $DIR/simplify-locals.rs:44:14: 44:15
|
|
||||||
StorageDead(_1); // scope 0 at $DIR/simplify-locals.rs:44:17: 44:18
|
|
||||||
_0 = const (); // scope 0 at $DIR/simplify-locals.rs:42:9: 45:2
|
_0 = const (); // scope 0 at $DIR/simplify-locals.rs:42:9: 45:2
|
||||||
return; // scope 0 at $DIR/simplify-locals.rs:45:2: 45:2
|
return; // scope 0 at $DIR/simplify-locals.rs:45:2: 45:2
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,18 +3,18 @@
|
||||||
|
|
||||||
fn t2() -> () {
|
fn t2() -> () {
|
||||||
let mut _0: (); // return place in scope 0 at $DIR/simplify-locals.rs:48:9: 48:9
|
let mut _0: (); // return place in scope 0 at $DIR/simplify-locals.rs:48:9: 48:9
|
||||||
let _1: &mut u32; // in scope 0 at $DIR/simplify-locals.rs:50:14: 50:20
|
- let _1: &mut u32; // in scope 0 at $DIR/simplify-locals.rs:50:14: 50:20
|
||||||
let mut _2: *mut u32; // in scope 0 at $DIR/simplify-locals.rs:50:19: 50:20
|
- let mut _2: *mut u32; // in scope 0 at $DIR/simplify-locals.rs:50:19: 50:20
|
||||||
scope 1 {
|
scope 1 {
|
||||||
}
|
}
|
||||||
|
|
||||||
bb0: {
|
bb0: {
|
||||||
StorageLive(_1); // scope 0 at $DIR/simplify-locals.rs:50:5: 50:22
|
- StorageLive(_1); // scope 0 at $DIR/simplify-locals.rs:50:5: 50:22
|
||||||
StorageLive(_2); // scope 1 at $DIR/simplify-locals.rs:50:19: 50:20
|
- StorageLive(_2); // scope 1 at $DIR/simplify-locals.rs:50:19: 50:20
|
||||||
_2 = &/*tls*/ mut X; // scope 1 at $DIR/simplify-locals.rs:50:19: 50:20
|
- _2 = &/*tls*/ mut X; // scope 1 at $DIR/simplify-locals.rs:50:19: 50:20
|
||||||
_1 = &mut (*_2); // scope 1 at $DIR/simplify-locals.rs:50:14: 50:20
|
- _1 = &mut (*_2); // scope 1 at $DIR/simplify-locals.rs:50:14: 50:20
|
||||||
StorageDead(_2); // scope 0 at $DIR/simplify-locals.rs:50:22: 50:23
|
- StorageDead(_2); // scope 0 at $DIR/simplify-locals.rs:50:22: 50:23
|
||||||
StorageDead(_1); // scope 0 at $DIR/simplify-locals.rs:50:22: 50:23
|
- StorageDead(_1); // scope 0 at $DIR/simplify-locals.rs:50:22: 50:23
|
||||||
_0 = const (); // scope 0 at $DIR/simplify-locals.rs:48:9: 51:2
|
_0 = const (); // scope 0 at $DIR/simplify-locals.rs:48:9: 51:2
|
||||||
return; // scope 0 at $DIR/simplify-locals.rs:51:2: 51:2
|
return; // scope 0 at $DIR/simplify-locals.rs:51:2: 51:2
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,6 @@
|
||||||
- let _1: u32; // in scope 0 at $DIR/simplify-locals.rs:56:14: 56:21
|
- let _1: u32; // in scope 0 at $DIR/simplify-locals.rs:56:14: 56:21
|
||||||
- let mut _2: &mut u32; // in scope 0 at $DIR/simplify-locals.rs:56:15: 56:21
|
- let mut _2: &mut u32; // in scope 0 at $DIR/simplify-locals.rs:56:15: 56:21
|
||||||
- let mut _3: *mut u32; // in scope 0 at $DIR/simplify-locals.rs:56:20: 56:21
|
- let mut _3: *mut u32; // in scope 0 at $DIR/simplify-locals.rs:56:20: 56:21
|
||||||
+ let mut _1: &mut u32; // in scope 0 at $DIR/simplify-locals.rs:56:15: 56:21
|
|
||||||
+ let mut _2: *mut u32; // in scope 0 at $DIR/simplify-locals.rs:56:20: 56:21
|
|
||||||
scope 1 {
|
scope 1 {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,12 +17,8 @@
|
||||||
- _2 = &mut (*_3); // scope 1 at $DIR/simplify-locals.rs:56:15: 56:21
|
- _2 = &mut (*_3); // scope 1 at $DIR/simplify-locals.rs:56:15: 56:21
|
||||||
- _1 = (*_2); // scope 1 at $DIR/simplify-locals.rs:56:14: 56:21
|
- _1 = (*_2); // scope 1 at $DIR/simplify-locals.rs:56:14: 56:21
|
||||||
- StorageDead(_3); // scope 0 at $DIR/simplify-locals.rs:56:23: 56:24
|
- StorageDead(_3); // scope 0 at $DIR/simplify-locals.rs:56:23: 56:24
|
||||||
+ StorageLive(_1); // scope 1 at $DIR/simplify-locals.rs:56:15: 56:21
|
- StorageDead(_2); // scope 0 at $DIR/simplify-locals.rs:56:23: 56:24
|
||||||
+ StorageLive(_2); // scope 1 at $DIR/simplify-locals.rs:56:20: 56:21
|
- StorageDead(_1); // scope 0 at $DIR/simplify-locals.rs:56:23: 56:24
|
||||||
+ _2 = &/*tls*/ mut X; // scope 1 at $DIR/simplify-locals.rs:56:20: 56:21
|
|
||||||
+ _1 = &mut (*_2); // scope 1 at $DIR/simplify-locals.rs:56:15: 56:21
|
|
||||||
StorageDead(_2); // scope 0 at $DIR/simplify-locals.rs:56:23: 56:24
|
|
||||||
StorageDead(_1); // scope 0 at $DIR/simplify-locals.rs:56:23: 56:24
|
|
||||||
_0 = const (); // scope 0 at $DIR/simplify-locals.rs:54:9: 57:2
|
_0 = const (); // scope 0 at $DIR/simplify-locals.rs:54:9: 57:2
|
||||||
return; // scope 0 at $DIR/simplify-locals.rs:57:2: 57:2
|
return; // scope 0 at $DIR/simplify-locals.rs:57:2: 57:2
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
// build-fail
|
// build-fail
|
||||||
// normalize-stderr-test: ".nll/" -> "/"
|
// normalize-stderr-test: ".nll/" -> "/"
|
||||||
|
// compile-flags: -Zmir-opt-level=0
|
||||||
|
|
||||||
struct S<T> {
|
struct S<T> {
|
||||||
t: T,
|
t: T,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue