Skip to content

Commit 5d13cbc

Browse files
committed
Tools and tests to experimentally add more counters per function
Adds a new mir_dump output file in HTML/CSS to visualize code regions and the MIR features that they came from (including overlapping spans). Adds `--bless` support to `test/run-make-fulldeps` so expected coverage output can be quickly regenerated. Adds a new `-Zexperimental-coverage` option that implies `-Zinstrument-coverage`, but can be used to enable experimental coverage counter injection. 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. Also, learned that `-C link-dead-code` (which was enabled automatically under `-Z instrument-coverage`) was causing the linking error that resulted in segmentation faults in coverage instrumented binaries. Link dead code is now disabled under MSVC, allowing `-Zinstrument-coverage` to be enabled under MSVC for the first time. Rust compiler MCP rust-lang/compiler-team#278 Relevant issue: #34701 - Implement support for LLVMs code coverage instrumentation
1 parent bf43421 commit 5d13cbc

File tree

53 files changed

+4108
-299
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+4108
-299
lines changed

library/profiler_builtins/build.rs

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ fn main() {
2020
"InstrProfilingMergeFile.c",
2121
"InstrProfilingNameVar.c",
2222
"InstrProfilingPlatformDarwin.c",
23+
"InstrProfilingPlatformFuchsia.c",
2324
"InstrProfilingPlatformLinux.c",
2425
"InstrProfilingPlatformOther.c",
2526
"InstrProfilingPlatformWindows.c",

src/librustc_codegen_ssa/back/link.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1668,7 +1668,7 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>(
16681668
// FIXME: Order dependent, applies to the following objects. Where should it be placed?
16691669
// Try to strip as much out of the generated object by removing unused
16701670
// sections if possible. See more comments in linker.rs
1671-
if sess.opts.cg.link_dead_code != Some(true) {
1671+
if !sess.link_dead_code() {
16721672
let keep_metadata = crate_type == CrateType::Dylib;
16731673
cmd.gc_sections(keep_metadata);
16741674
}

src/librustc_middle/mir/mod.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -1521,7 +1521,24 @@ impl Debug for Statement<'_> {
15211521
AscribeUserType(box (ref place, ref c_ty), ref variance) => {
15221522
write!(fmt, "AscribeUserType({:?}, {:?}, {:?})", place, variance, c_ty)
15231523
}
1524-
Coverage(box ref coverage) => write!(fmt, "{:?}", coverage),
1524+
Coverage(box ref coverage) => {
1525+
let rgn = &coverage.code_region;
1526+
match coverage.kind {
1527+
CoverageKind::Counter { id, .. } => {
1528+
write!(fmt, "Coverage counter({:?}) for {:?}", id.index(), rgn)
1529+
}
1530+
CoverageKind::Expression { id, lhs, op, rhs } => write!(
1531+
fmt,
1532+
"Coverage expr({:?}) = {} {} {} for {:?}",
1533+
id.index(),
1534+
lhs.index(),
1535+
if op == coverage::Op::Add { "+" } else { "-" },
1536+
rhs.index(),
1537+
rgn
1538+
),
1539+
CoverageKind::Unreachable => write!(fmt, "Coverage unreachable for {:?}", rgn),
1540+
}
1541+
}
15251542
Nop => write!(fmt, "nop"),
15261543
}
15271544
}

src/librustc_middle/mir/mono.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl<'tcx> MonoItem<'tcx> {
8686
.debugging_opts
8787
.inline_in_all_cgus
8888
.unwrap_or_else(|| tcx.sess.opts.optimize != OptLevel::No)
89-
&& tcx.sess.opts.cg.link_dead_code != Some(true);
89+
&& !tcx.sess.link_dead_code();
9090

9191
match *self {
9292
MonoItem::Fn(ref instance) => {

src/librustc_mir/monomorphize/partitioning/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ pub fn partition<'tcx>(
190190

191191
// Next we try to make as many symbols "internal" as possible, so LLVM has
192192
// more freedom to optimize.
193-
if tcx.sess.opts.cg.link_dead_code != Some(true) {
193+
if !tcx.sess.link_dead_code() {
194194
let _prof_timer = tcx.prof.generic_activity("cgu_partitioning_internalize_symbols");
195195
partitioner.internalize_symbols(tcx, &mut post_inlining, inlining_map);
196196
}
@@ -327,7 +327,7 @@ fn collect_and_partition_mono_items<'tcx>(
327327
}
328328
}
329329
None => {
330-
if tcx.sess.opts.cg.link_dead_code == Some(true) {
330+
if tcx.sess.link_dead_code() {
331331
MonoItemCollectionMode::Eager
332332
} else {
333333
MonoItemCollectionMode::Lazy

0 commit comments

Comments
 (0)