about summary refs log tree commit diff
diff options
context:
space:
mode:
authorWesley Wiser <wwiser@gmail.com>2019-06-03 21:52:26 -0400
committerWesley Wiser <wwiser@gmail.com>2019-06-06 08:31:54 -0400
commit1e50e01bb7c3200c48c8739435d4e7cece83ed6c (patch)
treecd78eb59c6a7d7cfd5d5f30fb4612f3beb9412e8
parent9f4d94b908d333161442c77314e1527eb8223a0e (diff)
downloadrust-1e50e01bb7c3200c48c8739435d4e7cece83ed6c.tar.gz
rust-1e50e01bb7c3200c48c8739435d4e7cece83ed6c.zip
[const-prop] Handle ProjectionElem::Deref
-rw-r--r--src/librustc_mir/transform/const_prop.rs6
-rw-r--r--src/test/mir-opt/const_prop/ref_deref.rs21
2 files changed, 27 insertions, 0 deletions
diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs
index 8e7093b833d..693fc9ba2f3 100644
--- a/src/librustc_mir/transform/const_prop.rs
+++ b/src/librustc_mir/transform/const_prop.rs
@@ -333,6 +333,12 @@ impl<'a, 'mir, 'tcx> ConstPropagator<'a, 'mir, 'tcx> {
                             this.ecx.operand_field(eval, field.index() as u64)
                         })?;
                     },
+                    ProjectionElem::Deref => {
+                        trace!("processing deref");
+                        eval = self.use_ecx(source_info, |this| {
+                            this.ecx.deref_operand(eval)
+                        })?.into();
+                    }
                     // We could get more projections by using e.g., `operand_projection`,
                     // but we do not even have the stack frame set up properly so
                     // an `Index` projection would throw us off-track.
diff --git a/src/test/mir-opt/const_prop/ref_deref.rs b/src/test/mir-opt/const_prop/ref_deref.rs
new file mode 100644
index 00000000000..2d04822c0e7
--- /dev/null
+++ b/src/test/mir-opt/const_prop/ref_deref.rs
@@ -0,0 +1,21 @@
+fn main() {
+    *(&4);
+}
+
+// END RUST SOURCE
+// START rustc.main.ConstProp.before.mir
+// bb0: {
+//     ...
+//     _2 = &(promoted[0]: i32);
+//     _1 = (*_2);
+//     ...
+//}
+// END rustc.main.ConstProp.before.mir
+// START rustc.main.ConstProp.after.mir
+// bb0: {
+//     ...
+//     _2 = const Scalar(AllocId(0).0x0) : &i32;
+//     _1 = const 4i32;
+//     ...
+// }
+// END rustc.main.ConstProp.after.mir