Auto merge of #105229 - saethlin:zst-writes-to-unions, r=oli-obk
Re-enable removal of ZST writes to unions This was previously disabled because Miri was lazily allocating unsized locals. But we aren't doing that anymore since https://github.com/rust-lang/rust/pull/98831, so we can have this optimization back.
This commit is contained in:
commit
e60fbaf4ce
6 changed files with 44 additions and 60 deletions
10
src/test/mir-opt/remove_zsts.get_union.PreCodegen.after.mir
Normal file
10
src/test/mir-opt/remove_zsts.get_union.PreCodegen.after.mir
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
// MIR for `get_union` after PreCodegen
|
||||
|
||||
fn get_union() -> Foo {
|
||||
let mut _0: Foo; // return place in scope 0 at $DIR/remove_zsts.rs:+0:19: +0:22
|
||||
|
||||
bb0: {
|
||||
Deinit(_0); // scope 0 at $DIR/remove_zsts.rs:+1:5: +1:18
|
||||
return; // scope 0 at $DIR/remove_zsts.rs:+2:2: +2:2
|
||||
}
|
||||
}
|
||||
19
src/test/mir-opt/remove_zsts.get_union.RemoveZsts.diff
Normal file
19
src/test/mir-opt/remove_zsts.get_union.RemoveZsts.diff
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
- // MIR for `get_union` before RemoveZsts
|
||||
+ // MIR for `get_union` after RemoveZsts
|
||||
|
||||
fn get_union() -> Foo {
|
||||
let mut _0: Foo; // return place in scope 0 at $DIR/remove_zsts.rs:+0:19: +0:22
|
||||
let mut _1: (); // in scope 0 at $DIR/remove_zsts.rs:+1:14: +1:16
|
||||
|
||||
bb0: {
|
||||
StorageLive(_1); // scope 0 at $DIR/remove_zsts.rs:+1:14: +1:16
|
||||
- Deinit(_1); // scope 0 at $DIR/remove_zsts.rs:+1:14: +1:16
|
||||
+ nop; // scope 0 at $DIR/remove_zsts.rs:+1:14: +1:16
|
||||
Deinit(_0); // scope 0 at $DIR/remove_zsts.rs:+1:5: +1:18
|
||||
- (_0.0: ()) = move _1; // scope 0 at $DIR/remove_zsts.rs:+1:5: +1:18
|
||||
+ nop; // scope 0 at $DIR/remove_zsts.rs:+1:5: +1:18
|
||||
StorageDead(_1); // scope 0 at $DIR/remove_zsts.rs:+1:17: +1:18
|
||||
return; // scope 0 at $DIR/remove_zsts.rs:+2:2: +2:2
|
||||
}
|
||||
}
|
||||
|
||||
14
src/test/mir-opt/remove_zsts.rs
Normal file
14
src/test/mir-opt/remove_zsts.rs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
union Foo {
|
||||
x: (),
|
||||
y: u64,
|
||||
}
|
||||
|
||||
// EMIT_MIR remove_zsts.get_union.RemoveZsts.diff
|
||||
// EMIT_MIR remove_zsts.get_union.PreCodegen.after.mir
|
||||
fn get_union() -> Foo {
|
||||
Foo { x: () }
|
||||
}
|
||||
|
||||
fn main() {
|
||||
get_union();
|
||||
}
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
// MIR for `get_union` after RemoveZsts
|
||||
|
||||
fn get_union() -> Foo {
|
||||
let mut _0: Foo; // return place in scope 0 at $DIR/remove_zsts_dont_touch_unions.rs:+0:19: +0:22
|
||||
let mut _1: (); // in scope 0 at $DIR/remove_zsts_dont_touch_unions.rs:+1:14: +1:16
|
||||
|
||||
bb0: {
|
||||
StorageLive(_1); // scope 0 at $DIR/remove_zsts_dont_touch_unions.rs:+1:14: +1:16
|
||||
nop; // scope 0 at $DIR/remove_zsts_dont_touch_unions.rs:+1:14: +1:16
|
||||
Deinit(_0); // scope 0 at $DIR/remove_zsts_dont_touch_unions.rs:+1:5: +1:18
|
||||
(_0.0: ()) = move _1; // scope 0 at $DIR/remove_zsts_dont_touch_unions.rs:+1:5: +1:18
|
||||
StorageDead(_1); // scope 0 at $DIR/remove_zsts_dont_touch_unions.rs:+1:17: +1:18
|
||||
return; // scope 0 at $DIR/remove_zsts_dont_touch_unions.rs:+2:2: +2:2
|
||||
}
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
// unit-test: RemoveZsts
|
||||
|
||||
// Ensure RemoveZsts doesn't remove ZST assignments to union fields,
|
||||
// which causes problems in Miri.
|
||||
|
||||
union Foo {
|
||||
x: (),
|
||||
y: u64,
|
||||
}
|
||||
|
||||
// EMIT_MIR remove_zsts_dont_touch_unions.get_union.RemoveZsts.after.mir
|
||||
fn get_union() -> Foo {
|
||||
Foo { x: () }
|
||||
}
|
||||
|
||||
|
||||
fn main() {
|
||||
get_union();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue