Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 97c58ed

Browse files
committed
avoid passing the gen/kill bits to start_block_effects
If the gen/kill bits are set there, the effects of `start_block_effects` will not be seen when using `FlowAtLocation` etc. to go over the MIR. EverInitializedLvals is the only pass that got this wrong, but this fixes the footgun for everyone.
1 parent 733e954 commit 97c58ed

File tree

4 files changed

+23
-23
lines changed

4 files changed

+23
-23
lines changed

src/librustc_mir/dataflow/impls/borrows.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ impl<'a, 'gcx, 'tcx> BitDenotation for Borrows<'a, 'gcx, 'tcx> {
213213
fn bits_per_block(&self) -> usize {
214214
self.borrows.len()
215215
}
216-
fn start_block_effect(&self, _sets: &mut BlockSets<BorrowIndex>) {
216+
fn start_block_effect(&self, _sets: &mut IdxSet<BorrowIndex>) {
217217
// no borrows of code region_scopes have been taken prior to
218218
// function execution, so this method has no effect on
219219
// `_sets`.

src/librustc_mir/dataflow/impls/mod.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -331,13 +331,12 @@ impl<'a, 'gcx, 'tcx> BitDenotation for MaybeInitializedLvals<'a, 'gcx, 'tcx> {
331331
self.move_data().move_paths.len()
332332
}
333333

334-
fn start_block_effect(&self, sets: &mut BlockSets<MovePathIndex>)
335-
{
334+
fn start_block_effect(&self, entry_set: &mut IdxSet<MovePathIndex>) {
336335
drop_flag_effects_for_function_entry(
337336
self.tcx, self.mir, self.mdpe,
338337
|path, s| {
339338
assert!(s == DropFlagState::Present);
340-
sets.on_entry.add(&path);
339+
entry_set.add(&path);
341340
});
342341
}
343342

@@ -384,15 +383,15 @@ impl<'a, 'gcx, 'tcx> BitDenotation for MaybeUninitializedLvals<'a, 'gcx, 'tcx> {
384383
}
385384

386385
// sets on_entry bits for Arg places
387-
fn start_block_effect(&self, sets: &mut BlockSets<MovePathIndex>) {
386+
fn start_block_effect(&self, entry_set: &mut IdxSet<MovePathIndex>) {
388387
// set all bits to 1 (uninit) before gathering counterevidence
389-
for e in sets.on_entry.words_mut() { *e = !0; }
388+
for e in entry_set.words_mut() { *e = !0; }
390389

391390
drop_flag_effects_for_function_entry(
392391
self.tcx, self.mir, self.mdpe,
393392
|path, s| {
394393
assert!(s == DropFlagState::Present);
395-
sets.on_entry.remove(&path);
394+
entry_set.remove(&path);
396395
});
397396
}
398397

@@ -439,14 +438,14 @@ impl<'a, 'gcx, 'tcx> BitDenotation for DefinitelyInitializedLvals<'a, 'gcx, 'tcx
439438
}
440439

441440
// sets on_entry bits for Arg places
442-
fn start_block_effect(&self, sets: &mut BlockSets<MovePathIndex>) {
443-
for e in sets.on_entry.words_mut() { *e = 0; }
441+
fn start_block_effect(&self, entry_set: &mut IdxSet<MovePathIndex>) {
442+
for e in entry_set.words_mut() { *e = 0; }
444443

445444
drop_flag_effects_for_function_entry(
446445
self.tcx, self.mir, self.mdpe,
447446
|path, s| {
448447
assert!(s == DropFlagState::Present);
449-
sets.on_entry.add(&path);
448+
entry_set.add(&path);
450449
});
451450
}
452451

@@ -492,10 +491,11 @@ impl<'a, 'gcx, 'tcx> BitDenotation for MovingOutStatements<'a, 'gcx, 'tcx> {
492491
self.move_data().moves.len()
493492
}
494493

495-
fn start_block_effect(&self, _sets: &mut BlockSets<MoveOutIndex>) {
494+
fn start_block_effect(&self, _sets: &mut IdxSet<MoveOutIndex>) {
496495
// no move-statements have been executed prior to function
497496
// execution, so this method has no effect on `_sets`.
498497
}
498+
499499
fn statement_effect(&self,
500500
sets: &mut BlockSets<MoveOutIndex>,
501501
location: Location) {
@@ -568,9 +568,12 @@ impl<'a, 'gcx, 'tcx> BitDenotation for EverInitializedLvals<'a, 'gcx, 'tcx> {
568568
self.move_data().inits.len()
569569
}
570570

571-
fn start_block_effect(&self, sets: &mut BlockSets<InitIndex>) {
572-
sets.gen_all((0..self.mir.arg_count).map(InitIndex::new));
571+
fn start_block_effect(&self, entry_set: &mut IdxSet<InitIndex>) {
572+
for arg_init in 0..self.mir.arg_count {
573+
entry_set.add(&InitIndex::new(arg_init));
574+
}
573575
}
576+
574577
fn statement_effect(&self,
575578
sets: &mut BlockSets<InitIndex>,
576579
location: Location) {

src/librustc_mir/dataflow/impls/storage_liveness.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl<'a, 'tcx> BitDenotation for MaybeStorageLive<'a, 'tcx> {
3636
self.mir.local_decls.len()
3737
}
3838

39-
fn start_block_effect(&self, _sets: &mut BlockSets<Local>) {
39+
fn start_block_effect(&self, _sets: &mut IdxSet<Local>) {
4040
// Nothing is live on function entry
4141
}
4242

src/librustc_mir/dataflow/mod.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ impl<'a, 'tcx: 'a, BD> DataflowAnalysis<'a, 'tcx, BD> where BD: BitDenotation
171171

172172
{
173173
let sets = &mut self.flow_state.sets.for_block(mir::START_BLOCK.index());
174-
self.flow_state.operator.start_block_effect(sets);
174+
self.flow_state.operator.start_block_effect(&mut sets.on_entry);
175175
}
176176

177177
for (bb, data) in self.mir.basic_blocks().iter_enumerated() {
@@ -556,16 +556,13 @@ pub trait BitDenotation: DataflowOperator {
556556
/// Size of each bitvector allocated for each block in the analysis.
557557
fn bits_per_block(&self) -> usize;
558558

559-
/// Mutates the block-sets (the flow sets for the given
560-
/// basic block) according to the effects that have been
561-
/// established *prior* to entering the start block.
559+
/// Mutates the entry set according to the effects that
560+
/// have been established *prior* to entering the start
561+
/// block. This can't access the gen/kill sets, because
562+
/// these won't be accounted for correctly.
562563
///
563564
/// (For example, establishing the call arguments.)
564-
///
565-
/// (Typically this should only modify `sets.on_entry`, since the
566-
/// gen and kill sets should reflect the effects of *executing*
567-
/// the start block itself.)
568-
fn start_block_effect(&self, sets: &mut BlockSets<Self::Idx>);
565+
fn start_block_effect(&self, entry_set: &mut IdxSet<Self::Idx>);
569566

570567
/// Mutates the block-sets (the flow sets for the given
571568
/// basic block) according to the effects of evaluating statement.

0 commit comments

Comments
 (0)