about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-03-25 07:48:52 +0000
committerbors <bors@rust-lang.org>2021-03-25 07:48:52 +0000
commit372afcf93bf60e1a9334b107cc3d72f1b0a4b1f4 (patch)
tree2b1b259bfc25a7d87f4f8d9b9e16b36628758853 /src/test
parentdbc37a97dcf08984163133cff85af5190af037ca (diff)
parentd5c1ad5ca1c014044a4bfd5c9c82fb277de304c3 (diff)
downloadrust-372afcf93bf60e1a9334b107cc3d72f1b0a4b1f4.tar.gz
rust-372afcf93bf60e1a9334b107cc3d72f1b0a4b1f4.zip
Auto merge of #83445 - erikdesjardins:rmunion, r=RalfJung
RemoveZsts: don't touch unions

This should fix a Miri ICE

r? `@RalfJung`
Diffstat (limited to 'src/test')
-rw-r--r--src/test/mir-opt/remove_zsts_dont_touch_unions.get_union.RemoveZsts.after.mir13
-rw-r--r--src/test/mir-opt/remove_zsts_dont_touch_unions.rs19
2 files changed, 32 insertions, 0 deletions
diff --git a/src/test/mir-opt/remove_zsts_dont_touch_unions.get_union.RemoveZsts.after.mir b/src/test/mir-opt/remove_zsts_dont_touch_unions.get_union.RemoveZsts.after.mir
new file mode 100644
index 00000000000..33bd9eb9b19
--- /dev/null
+++ b/src/test/mir-opt/remove_zsts_dont_touch_unions.get_union.RemoveZsts.after.mir
@@ -0,0 +1,13 @@
+// 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:12:19: 12:22
+    let mut _1: ();                      // in scope 0 at $DIR/remove_zsts_dont_touch_unions.rs:13:14: 13:16
+
+    bb0: {
+        StorageLive(_1);                 // scope 0 at $DIR/remove_zsts_dont_touch_unions.rs:13:14: 13:16
+        (_0.0: ()) = move _1;            // scope 0 at $DIR/remove_zsts_dont_touch_unions.rs:13:5: 13:18
+        StorageDead(_1);                 // scope 0 at $DIR/remove_zsts_dont_touch_unions.rs:13:17: 13:18
+        return;                          // scope 0 at $DIR/remove_zsts_dont_touch_unions.rs:14:2: 14:2
+    }
+}
diff --git a/src/test/mir-opt/remove_zsts_dont_touch_unions.rs b/src/test/mir-opt/remove_zsts_dont_touch_unions.rs
new file mode 100644
index 00000000000..7a6f86b8085
--- /dev/null
+++ b/src/test/mir-opt/remove_zsts_dont_touch_unions.rs
@@ -0,0 +1,19 @@
+// compile-flags: -Zmir-opt-level=3
+
+// 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();
+}