Only generate dummy assign when instrumenting coverage
And make the LocalDecl internal, to avoid needing to declare storage. (For multiple `continue` stateuemtns, it must also be mutable.)
This commit is contained in:
parent
448e52d97c
commit
d1d7fb1ae5
2 changed files with 15 additions and 14 deletions
|
@ -618,16 +618,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
assert!(value.is_none(), "`return` and `break` should have a destination");
|
assert!(value.is_none(), "`return` and `break` should have a destination");
|
||||||
// `continue` statements generate no MIR statement with the `continue` statement's Span,
|
if self.tcx.sess.instrument_coverage() {
|
||||||
// and the `InstrumentCoverage` statement will have no way to generate a coverage
|
// Unlike `break` and `return`, which push an `Assign` statement to MIR, from which
|
||||||
// code region for the `continue` statement, unless we add a dummy `Assign` here:
|
// a Coverage code region can be generated, `continue` needs no `Assign`; but
|
||||||
let mut local_decl = LocalDecl::new(self.tcx.mk_unit(), span);
|
// without one, the `InstrumentCoverage` MIR pass cannot generate a code region for
|
||||||
local_decl = local_decl.immutable();
|
// `continue`. Coverage will be missing unless we add a dummy `Assign` to MIR.
|
||||||
let temp = self.local_decls.push(local_decl);
|
self.add_dummy_assignment(&span, block, source_info);
|
||||||
let temp_place = Place::from(temp);
|
}
|
||||||
self.cfg.push(block, Statement { source_info, kind: StatementKind::StorageLive(temp) });
|
|
||||||
self.cfg.push_assign_unit(block, source_info, temp_place, self.tcx);
|
|
||||||
self.cfg.push(block, Statement { source_info, kind: StatementKind::StorageDead(temp) });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let region_scope = self.scopes.breakable_scopes[break_index].region_scope;
|
let region_scope = self.scopes.breakable_scopes[break_index].region_scope;
|
||||||
|
@ -653,6 +650,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||||
self.cfg.start_new_block().unit()
|
self.cfg.start_new_block().unit()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add a dummy `Assign` statement to the CFG, with the span for the source code's `continue`
|
||||||
|
// statement.
|
||||||
|
fn add_dummy_assignment(&mut self, span: &Span, block: BasicBlock, source_info: SourceInfo) {
|
||||||
|
let local_decl = LocalDecl::new(self.tcx.mk_unit(), *span).internal();
|
||||||
|
let temp_place = Place::from(self.local_decls.push(local_decl));
|
||||||
|
self.cfg.push_assign_unit(block, source_info, temp_place, self.tcx);
|
||||||
|
}
|
||||||
|
|
||||||
crate fn exit_top_scope(
|
crate fn exit_top_scope(
|
||||||
&mut self,
|
&mut self,
|
||||||
mut block: BasicBlock,
|
mut block: BasicBlock,
|
||||||
|
|
|
@ -8,7 +8,6 @@ fn main() -> () {
|
||||||
let mut _4: !; // in scope 0 at $DIR/loop_test.rs:13:5: 16:6
|
let mut _4: !; // in scope 0 at $DIR/loop_test.rs:13:5: 16:6
|
||||||
let mut _5: (); // in scope 0 at $DIR/loop_test.rs:6:1: 17:2
|
let mut _5: (); // in scope 0 at $DIR/loop_test.rs:6:1: 17:2
|
||||||
let _6: i32; // in scope 0 at $DIR/loop_test.rs:14:13: 14:14
|
let _6: i32; // in scope 0 at $DIR/loop_test.rs:14:13: 14:14
|
||||||
let _7: (); // in scope 0 at $DIR/loop_test.rs:15:9: 15:17
|
|
||||||
scope 1 {
|
scope 1 {
|
||||||
debug x => _6; // in scope 1 at $DIR/loop_test.rs:14:13: 14:14
|
debug x => _6; // in scope 1 at $DIR/loop_test.rs:14:13: 14:14
|
||||||
}
|
}
|
||||||
|
@ -43,9 +42,6 @@ fn main() -> () {
|
||||||
StorageLive(_6); // scope 0 at $DIR/loop_test.rs:14:13: 14:14
|
StorageLive(_6); // scope 0 at $DIR/loop_test.rs:14:13: 14:14
|
||||||
_6 = const 1_i32; // scope 0 at $DIR/loop_test.rs:14:17: 14:18
|
_6 = const 1_i32; // scope 0 at $DIR/loop_test.rs:14:17: 14:18
|
||||||
FakeRead(ForLet(None), _6); // scope 0 at $DIR/loop_test.rs:14:13: 14:14
|
FakeRead(ForLet(None), _6); // scope 0 at $DIR/loop_test.rs:14:13: 14:14
|
||||||
StorageLive(_7); // scope 1 at $DIR/loop_test.rs:15:9: 15:17
|
|
||||||
_7 = const (); // scope 1 at $DIR/loop_test.rs:15:9: 15:17
|
|
||||||
StorageDead(_7); // scope 1 at $DIR/loop_test.rs:15:9: 15:17
|
|
||||||
StorageDead(_6); // scope 0 at $DIR/loop_test.rs:16:5: 16:6
|
StorageDead(_6); // scope 0 at $DIR/loop_test.rs:16:5: 16:6
|
||||||
goto -> bb3; // scope 0 at $DIR/loop_test.rs:1:1: 1:1
|
goto -> bb3; // scope 0 at $DIR/loop_test.rs:1:1: 1:1
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue