]> git.lizzy.rs Git - rust.git/commitdiff
[const-prop] Handle ProjectionElem::Deref
authorWesley Wiser <wwiser@gmail.com>
Tue, 4 Jun 2019 01:52:26 +0000 (21:52 -0400)
committerWesley Wiser <wwiser@gmail.com>
Thu, 6 Jun 2019 12:31:54 +0000 (08:31 -0400)
src/librustc_mir/transform/const_prop.rs
src/test/mir-opt/const_prop/ref_deref.rs [new file with mode: 0644]

index 8e7093b833d441e3f678005b2e079a0ddd769593..693fc9ba2f327bba657d40195b8cfeff7f45a2e9 100644 (file)
@@ -333,6 +333,12 @@ fn eval_place(&mut self, place: &Place<'tcx>, source_info: SourceInfo) -> Option
                             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 (file)
index 0000000..2d04822
--- /dev/null
@@ -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