Combination of commits

Fixes multiple issue with counters, with simplification

  Includes a change to the implicit else span in ast_lowering, so coverage
  of the implicit else no longer spans the `then` block.

  Adds coverage for unused closures and async function bodies.

  Fixes: #78542

Adding unreachable regions for known MIR missing from coverage map

Cleaned up PR commits, and removed link-dead-code requirement and tests

  Coverage no longer depends on Issue #76038 (`-C link-dead-code` is
  no longer needed or enforced, so MSVC can use the same tests as
  Linux and MacOS now)

Restrict adding unreachable regions to covered files

  Improved the code that adds coverage for uncalled functions (with MIR
  but not-codegenned) to avoid generating coverage in files not already
  included in the files with covered functions.

Resolved last known issue requiring --emit llvm-ir workaround

  Fixed bugs in how unreachable code spans were added.
This commit is contained in:
Rich Kadel 2020-11-30 23:58:08 -08:00
parent f6c9c1a576
commit def932ca86
354 changed files with 12634 additions and 20486 deletions

View file

@ -945,8 +945,7 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
"instrument the generated code to support LLVM source-based code coverage \
reports (note, the compiler build config must include `profiler = true`, \
and is mutually exclusive with `-C profile-generate`/`-C profile-use`); \
implies `-C link-dead-code` (unless targeting MSVC, or explicitly disabled) \
and `-Z symbol-mangling-version=v0`; disables/overrides some Rust \
implies `-Z symbol-mangling-version=v0`; disables/overrides some Rust \
optimizations (default: no)"),
instrument_mcount: bool = (false, parse_bool, [TRACKED],
"insert function instrument code for mcount-based tracing (default: no)"),

View file

@ -1111,33 +1111,7 @@ impl Session {
pub fn link_dead_code(&self) -> bool {
match self.opts.cg.link_dead_code {
Some(explicitly_set) => explicitly_set,
None => {
self.opts.debugging_opts.instrument_coverage && !self.target.is_like_msvc
// Issue #76038: (rustc `-Clink-dead-code` causes MSVC linker to produce invalid
// binaries when LLVM InstrProf counters are enabled). As described by this issue,
// the "link dead code" option produces incorrect binaries when compiled and linked
// under MSVC. The resulting Rust programs typically crash with a segmentation
// fault, or produce an empty "*.profraw" file (profiling counter results normally
// generated during program exit).
//
// If not targeting MSVC, `-Z instrument-coverage` implies `-C link-dead-code`, so
// unexecuted code is still counted as zero, rather than be optimized out. Note that
// instrumenting dead code can be explicitly disabled with:
//
// `-Z instrument-coverage -C link-dead-code=no`.
//
// FIXME(richkadel): Investigate if `instrument-coverage` implementation can inject
// [zero counters](https://llvm.org/docs/CoverageMappingFormat.html#counter) in the
// coverage map when "dead code" is removed, rather than forcing `link-dead-code`.
// This may not be possible, however, if (as it seems to appear) the "dead code"
// that would otherwise not be linked is only identified as "dead" by the native
// linker. If that's the case, I believe it is too late for the Rust compiler to
// leverage any information it might be able to get from the linker regarding what
// code is dead, to be able to add those counters.
//
// On the other hand, if any Rust compiler passes are optimizing out dead code blocks
// we should inject "zero" counters for those code regions.
}
None => false,
}
}