summaryrefslogtreecommitdiffstats
path: root/tests/mir-opt/simplify_locals.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:18:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:18:58 +0000
commita4b7ed7a42c716ab9f05e351f003d589124fd55d (patch)
treeb620cd3f223850b28716e474e80c58059dca5dd4 /tests/mir-opt/simplify_locals.rs
parentAdding upstream version 1.67.1+dfsg1. (diff)
downloadrustc-a4b7ed7a42c716ab9f05e351f003d589124fd55d.tar.xz
rustc-a4b7ed7a42c716ab9f05e351f003d589124fd55d.zip
Adding upstream version 1.68.2+dfsg1.upstream/1.68.2+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/mir-opt/simplify_locals.rs')
-rw-r--r--tests/mir-opt/simplify_locals.rs81
1 files changed, 81 insertions, 0 deletions
diff --git a/tests/mir-opt/simplify_locals.rs b/tests/mir-opt/simplify_locals.rs
new file mode 100644
index 000000000..7bbc0481c
--- /dev/null
+++ b/tests/mir-opt/simplify_locals.rs
@@ -0,0 +1,81 @@
+// unit-test: SimplifyLocals-before-const-prop
+
+
+#![feature(thread_local)]
+
+#[derive(Copy, Clone)]
+enum E {
+ A,
+ B,
+}
+
+// EMIT_MIR simplify_locals.c.SimplifyLocals-before-const-prop.diff
+fn c() {
+ let bytes = [0u8; 10];
+ // Unused cast
+ let _: &[u8] = &bytes;
+}
+
+// EMIT_MIR simplify_locals.d1.SimplifyLocals-before-const-prop.diff
+fn d1() {
+ // Unused set discriminant
+ let _ = E::A;
+}
+
+// EMIT_MIR simplify_locals.d2.SimplifyLocals-before-const-prop.diff
+fn d2() {
+ // Unused set discriminant
+ {(10, E::A)}.1 = E::B;
+}
+
+// EMIT_MIR simplify_locals.r.SimplifyLocals-before-const-prop.diff
+fn r() {
+ let mut a = 1;
+ // Unused references
+ let _ = &a;
+ let _ = &mut a;
+}
+
+#[thread_local] static mut X: u32 = 0;
+
+// EMIT_MIR simplify_locals.t1.SimplifyLocals-before-const-prop.diff
+fn t1() {
+ // Unused thread local
+ unsafe { X };
+}
+
+// EMIT_MIR simplify_locals.t2.SimplifyLocals-before-const-prop.diff
+fn t2() {
+ // Unused thread local
+ unsafe { &mut X };
+}
+
+// EMIT_MIR simplify_locals.t3.SimplifyLocals-before-const-prop.diff
+fn t3() {
+ // Unused thread local
+ unsafe { *&mut X };
+}
+
+// EMIT_MIR simplify_locals.t4.SimplifyLocals-before-const-prop.diff
+fn t4() -> u32 {
+ // Used thread local
+ unsafe { X + 1 }
+}
+
+// EMIT_MIR simplify_locals.expose_addr.SimplifyLocals-before-const-prop.diff
+fn expose_addr(p: *const usize) {
+ // Used pointer to address cast. Has a side effect of exposing the provenance.
+ p as usize;
+}
+
+fn main() {
+ c();
+ d1();
+ d2();
+ r();
+ t1();
+ t2();
+ t3();
+ t4();
+ expose_addr(&0);
+}