Skip to content

Commit 1e50e01

Browse files
committed
[const-prop] Handle ProjectionElem::Deref
1 parent 9f4d94b commit 1e50e01

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/librustc_mir/transform/const_prop.rs

+6
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,12 @@ impl<'a, 'mir, 'tcx> ConstPropagator<'a, 'mir, 'tcx> {
333333
this.ecx.operand_field(eval, field.index() as u64)
334334
})?;
335335
},
336+
ProjectionElem::Deref => {
337+
trace!("processing deref");
338+
eval = self.use_ecx(source_info, |this| {
339+
this.ecx.deref_operand(eval)
340+
})?.into();
341+
}
336342
// We could get more projections by using e.g., `operand_projection`,
337343
// but we do not even have the stack frame set up properly so
338344
// an `Index` projection would throw us off-track.
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
fn main() {
2+
*(&4);
3+
}
4+
5+
// END RUST SOURCE
6+
// START rustc.main.ConstProp.before.mir
7+
// bb0: {
8+
// ...
9+
// _2 = &(promoted[0]: i32);
10+
// _1 = (*_2);
11+
// ...
12+
//}
13+
// END rustc.main.ConstProp.before.mir
14+
// START rustc.main.ConstProp.after.mir
15+
// bb0: {
16+
// ...
17+
// _2 = const Scalar(AllocId(0).0x0) : &i32;
18+
// _1 = const 4i32;
19+
// ...
20+
// }
21+
// END rustc.main.ConstProp.after.mir

0 commit comments

Comments
 (0)