Skip to content

Commit b851e55

Browse files
committed
Support CopyForDeref.
1 parent 82f0468 commit b851e55

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

compiler/rustc_mir_transform/src/dataflow_const_prop.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ impl<'tcx> ValueAnalysis<'tcx> for ConstAnalysis<'_, 'tcx> {
119119
self.assign_operand(state, target, operand);
120120
}
121121
}
122+
Rvalue::CopyForDeref(rhs) => {
123+
state.flood(target.as_ref(), self.map());
124+
if let Some(target) = self.map.find(target.as_ref()) {
125+
self.assign_operand(state, target, &Operand::Copy(*rhs));
126+
}
127+
}
122128
Rvalue::Aggregate(kind, operands) => {
123129
// If we assign `target = Enum::Variant#0(operand)`,
124130
// we must make sure that all `target as Variant#i` are `Top`.

tests/mir-opt/dataflow-const-prop/struct.main.DataflowConstProp.diff

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,20 @@
8888
_17 = deref_copy (*_16);
8989
StorageLive(_12);
9090
_18 = deref_copy (*_16);
91-
_12 = ((*_18).0: S);
91+
- _12 = ((*_18).0: S);
92+
+ _12 = const S(1_i32);
9293
StorageLive(_13);
9394
_19 = deref_copy (*_16);
94-
_13 = ((*_19).1: u8);
95+
- _13 = ((*_19).1: u8);
96+
+ _13 = const 5_u8;
9597
StorageLive(_14);
9698
_20 = deref_copy (*_16);
97-
_14 = ((*_20).2: f32);
99+
- _14 = ((*_20).2: f32);
100+
+ _14 = const 7f32;
98101
StorageLive(_15);
99102
_21 = deref_copy (*_16);
100-
_15 = ((*_21).3: S);
103+
- _15 = ((*_21).3: S);
104+
+ _15 = const S(13_i32);
101105
StorageDead(_16);
102106
_0 = const ();
103107
StorageDead(_15);

0 commit comments

Comments
 (0)