Skip to content

Commit

Permalink
Auto merge of #76004 - richkadel:llvm-coverage-map-gen-6b.5, r=tmandry
Browse files Browse the repository at this point in the history
Tools, tests, and experimenting with MIR-derived coverage counters

Leverages the new mir_dump output file in HTML+CSS (from #76074) to visualize coverage code regions
and the MIR features that they came from (including overlapping spans).

See example below.

The `run-make-fulldeps/instrument-coverage` test has been refactored to maximize test coverage and reduce code duplication. The new tests support testing with and without `-Clink-dead-code`, so Rust coverage can be tested on MSVC (which, currently, only works with `link-dead-code` _disabled_).

New tests validate coverage region generation and coverage reports with multiple counters per function. Starting with a simple `if-else` branch tests, coverage tests for each additional syntax type can be added by simply dropping in a new Rust sample program.

Includes a basic, MIR-block-based implementation of coverage injection,
available via `-Zexperimental-coverage`. This implementation has known
flaws and omissions, but is simple enough to validate the new tools and
tests.

The existing `-Zinstrument-coverage` option currently enables
function-level coverage only, which at least appears to generate
accurate coverage reports at that level.

Experimental coverage is not accurate at this time. When branch coverage
works as intended, the `-Zexperimental-coverage` option should be
removed.

This PR replaces the bulk of PR #75828, with the remaining parts of
that PR distributed among other separate and indentpent PRs.

This PR depends on two of those other PRs: #76002, #76003 and #76074

Rust compiler MCP rust-lang/compiler-team#278

Relevant issue: #34701 - Implement support for LLVMs code coverage
instrumentation

![Screen-Recording-2020-08-21-at-2](https://user-images.githubusercontent.com/3827298/90972923-ff417880-e4d1-11ea-92bb-8713c6198f6d.gif)

r? @tmandry
FYI: @wesleywiser
  • Loading branch information
bors committed Sep 4, 2020
2 parents af3c6e7 + 51d692c commit 4ffb5c5
Show file tree
Hide file tree
Showing 28 changed files with 2,072 additions and 299 deletions.
19 changes: 18 additions & 1 deletion compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1530,7 +1530,24 @@ impl Debug for Statement<'_> {
AscribeUserType(box (ref place, ref c_ty), ref variance) => {
write!(fmt, "AscribeUserType({:?}, {:?}, {:?})", place, variance, c_ty)
}
Coverage(box ref coverage) => write!(fmt, "{:?}", coverage),
Coverage(box ref coverage) => {
let rgn = &coverage.code_region;
match coverage.kind {
CoverageKind::Counter { id, .. } => {
write!(fmt, "Coverage::Counter({:?}) for {:?}", id.index(), rgn)
}
CoverageKind::Expression { id, lhs, op, rhs } => write!(
fmt,
"Coverage::Expression({:?}) = {} {} {} for {:?}",
id.index(),
lhs.index(),
if op == coverage::Op::Add { "+" } else { "-" },
rhs.index(),
rgn
),
CoverageKind::Unreachable => write!(fmt, "Coverage::Unreachable for {:?}", rgn),
}
}
Nop => write!(fmt, "nop"),
}
}
Expand Down
Loading

0 comments on commit 4ffb5c5

Please sign in to comment.