about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2021-10-05 12:52:48 -0700
committerGitHub <noreply@github.com>2021-10-05 12:52:48 -0700
commitf71b3e2b46505fda8dea7187fa90b80472f7abfa (patch)
treefbf28a75f29d4f004795e4adf0a826fc81e01f30 /src/test
parent048b0fd98df7ed3351e4c133eda4f683cb872956 (diff)
parent9f9f7f695a793c5ef27d219dbd00c66810f34e92 (diff)
downloadrust-f71b3e2b46505fda8dea7187fa90b80472f7abfa.tar.gz
rust-f71b3e2b46505fda8dea7187fa90b80472f7abfa.zip
Rollup merge of #89532 - ecstatic-morse:maybe-live-locals-enum, r=oli-obk,tmiasko
Document behavior of  `MaybeLiveLocals` regarding enums and field-senstivity

This arose from a [discussion on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/MaybeLiveLocals.20and.20Discriminants) where a new contributor attempted to implement a dead-store elimination pass using this analysis. They ran into a nasty hack around `SetDiscriminant` the effect of which is to lets handle assignments of literals to enum-typed locals (e.g. `x = Some(4)`) correctly. This took me a while to figure out.

Document this oddity, so the next person will have an easier time, and add a test to enshrine the current behavior.

r? ``@tmiasko``
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/mir-dataflow/liveness-enum.rs22
-rw-r--r--src/test/ui/mir-dataflow/liveness-enum.stderr10
2 files changed, 32 insertions, 0 deletions
diff --git a/src/test/ui/mir-dataflow/liveness-enum.rs b/src/test/ui/mir-dataflow/liveness-enum.rs
new file mode 100644
index 00000000000..5eb04ae8c8d
--- /dev/null
+++ b/src/test/ui/mir-dataflow/liveness-enum.rs
@@ -0,0 +1,22 @@
+#![feature(core_intrinsics, rustc_attrs)]
+
+use std::intrinsics::rustc_peek;
+
+#[rustc_mir(rustc_peek_liveness, stop_after_dataflow)]
+fn foo() -> Option<i32> {
+    let mut x = None;
+
+    // `x` is live here since it is used in the next statement...
+    rustc_peek(x);
+
+    dbg!(x);
+
+    // But not here, since it is overwritten below
+    rustc_peek(x); //~ ERROR rustc_peek: bit not set
+
+    x = Some(4);
+
+    x
+}
+
+fn main() {}
diff --git a/src/test/ui/mir-dataflow/liveness-enum.stderr b/src/test/ui/mir-dataflow/liveness-enum.stderr
new file mode 100644
index 00000000000..483944d731a
--- /dev/null
+++ b/src/test/ui/mir-dataflow/liveness-enum.stderr
@@ -0,0 +1,10 @@
+error: rustc_peek: bit not set
+  --> $DIR/liveness-enum.rs:15:5
+   |
+LL |     rustc_peek(x);
+   |     ^^^^^^^^^^^^^
+
+error: stop_after_dataflow ended compilation
+
+error: aborting due to 2 previous errors
+