1
Fork 0

Add coverage to continue statements

`continue` statements were missing coverage. This was particularly
noticeable in a match pattern that contained only a `continue`
statement, leaving the branch appear uncounted. This PR addresses the
problem and adds tests to prove it.
This commit is contained in:
Rich Kadel 2021-04-18 02:55:17 -07:00
parent 83ca4b7e60
commit 448e52d97c
5 changed files with 160 additions and 2 deletions

View file

@ -618,6 +618,16 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
}
} else {
assert!(value.is_none(), "`return` and `break` should have a destination");
// `continue` statements generate no MIR statement with the `continue` statement's Span,
// and the `InstrumentCoverage` statement will have no way to generate a coverage
// code region for the `continue` statement, unless we add a dummy `Assign` here:
let mut local_decl = LocalDecl::new(self.tcx.mk_unit(), span);
local_decl = local_decl.immutable();
let temp = self.local_decls.push(local_decl);
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;