Skip to content

Commit 7213eaa

Browse files
committed
Flood aggregate assignments with Top.
1 parent 6506837 commit 7213eaa

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

compiler/rustc_mir_transform/src/dataflow_const_prop.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,10 @@ impl<'tcx> ValueAnalysis<'tcx> for ConstAnalysis<'_, 'tcx> {
122122
) {
123123
match rvalue {
124124
Rvalue::Aggregate(kind, operands) => {
125-
state.flood_with(target.as_ref(), self.map(), FlatSet::Bottom);
125+
// If we assign `target = Enum::Variant#0(operand)`,
126+
// we must make sure that all `target as Variant#i` are `Top`.
127+
state.flood(target.as_ref(), self.map());
128+
126129
if let Some(target_idx) = self.map().find(target.as_ref()) {
127130
let (variant_target, variant_index) = match **kind {
128131
AggregateKind::Tuple | AggregateKind::Closure(..) => {

tests/mir-opt/dataflow-const-prop/enum.multiple.DataflowConstProp.diff

+1-2
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@
7171

7272
bb7: {
7373
StorageLive(_9); // scope 2 at $DIR/enum.rs:+11:9: +11:10
74-
- _9 = _6; // scope 2 at $DIR/enum.rs:+11:13: +11:14
75-
+ _9 = const 0_u8; // scope 2 at $DIR/enum.rs:+11:13: +11:14
74+
_9 = _6; // scope 2 at $DIR/enum.rs:+11:13: +11:14
7675
_0 = const (); // scope 0 at $DIR/enum.rs:+0:29: +12:2
7776
StorageDead(_9); // scope 2 at $DIR/enum.rs:+12:1: +12:2
7877
StorageDead(_6); // scope 1 at $DIR/enum.rs:+12:1: +12:2

0 commit comments

Comments
 (0)