Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work around missing code coverage data causing llvm-cov failures #93144

Merged
merged 1 commit into from
Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use rustc_data_structures::fx::FxIndexSet;
use rustc_hir::def::DefKind;
use rustc_hir::def_id::DefIdSet;
use rustc_llvm::RustString;
use rustc_middle::bug;
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use rustc_middle::mir::coverage::CodeRegion;
use rustc_middle::ty::TyCtxt;
Expand Down Expand Up @@ -76,10 +77,18 @@ pub fn finalize<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>) {
let coverage_mapping_buffer = llvm::build_byte_buffer(|coverage_mapping_buffer| {
mapgen.write_coverage_mapping(expressions, counter_regions, coverage_mapping_buffer);
});
debug_assert!(
!coverage_mapping_buffer.is_empty(),
"Every `FunctionCoverage` should have at least one counter"
);

wesleywiser marked this conversation as resolved.
Show resolved Hide resolved
if coverage_mapping_buffer.is_empty() {
if function_coverage.is_used() {
bug!(
"A used function should have had coverage mapping data but did not: {}",
mangled_function_name
);
} else {
debug!("unused function had no coverage mapping data: {}", mangled_function_name);
continue;
}
}

function_data.push((mangled_function_name, source_hash, is_used, coverage_mapping_buffer));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
1| |// Regression test for #93054: Functions using uninhabited types often only have a single,
2| |// unreachable basic block which doesn't get instrumented. This should not cause llvm-cov to fail.
3| |// Since these kinds functions can't be invoked anyway, it's ok to not have coverage data for them.
4| |
5| |// compile-flags: --edition=2021
6| |
7| |enum Never { }
8| |
9| |impl Never {
10| | fn foo(self) {
11| | match self { }
12| | make().map(|never| match never { });
13| | }
14| |
15| | fn bar(&self) {
16| | match *self { }
17| | }
18| |}
19| |
20| 0|async fn foo2(never: Never) {
21| | match never { }
22| |}
23| |
24| 0|fn make() -> Option<Never> {
25| 0| None
26| 0|}
27| |
28| 1|fn main() { }

28 changes: 28 additions & 0 deletions src/test/run-make-fulldeps/coverage/issue-93054.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Regression test for #93054: Functions using uninhabited types often only have a single,
// unreachable basic block which doesn't get instrumented. This should not cause llvm-cov to fail.
// Since these kinds functions can't be invoked anyway, it's ok to not have coverage data for them.

// compile-flags: --edition=2021

enum Never { }

impl Never {
fn foo(self) {
match self { }
make().map(|never| match never { });
}

fn bar(&self) {
match *self { }
}
}

async fn foo2(never: Never) {
match never { }
}

fn make() -> Option<Never> {
None
}

fn main() { }