rust/tests/run-coverage/issue-93054.coverage

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

32 lines
1.0 KiB
Plaintext
Raw Normal View History

LL| |#![allow(dead_code, unreachable_code)]
LL| |
LL| |// Regression test for #93054: Functions using uninhabited types often only have a single,
LL| |// unreachable basic block which doesn't get instrumented. This should not cause llvm-cov to fail.
LL| |// Since these kinds functions can't be invoked anyway, it's ok to not have coverage data for them.
LL| |
LL| |// compile-flags: --edition=2021
LL| |
LL| |enum Never {}
LL| |
LL| |impl Never {
LL| | fn foo(self) {
LL| | match self {}
LL| | make().map(|never| match never {});
LL| | }
LL| |
LL| | fn bar(&self) {
LL| | match *self {}
LL| | }
LL| |}
LL| |
LL| 0|async fn foo2(never: Never) {
LL| | match never {}
LL| |}
LL| |
LL| 0|fn make() -> Option<Never> {
LL| 0| None
LL| 0|}
LL| |
LL| 1|fn main() {}
Work around missing code coverage data causing llvm-cov failures If we do not add code coverage instrumentation to the `Body` of a function, then when we go to generate the function record for it, we won't write any data and this later causes llvm-cov to fail when processing data for the entire coverage report. I've identified two main cases where we do not currently add code coverage instrumentation to the `Body` of a function: 1. If the function has a single `BasicBlock` and it ends with a `TerminatorKind::Unreachable`. 2. If the function is created using a proc macro of some kind. For case 1, this typically not important as this most often occurs as the result of function definitions that take or return uninhabited types. These kinds of functions, by definition, cannot even be called so they logically should not be counted in code coverage statistics. For case 2, I haven't looked into this very much but I've noticed while testing this patch that (other than functions which are covered by case 1) the skipped function coverage debug message is occasionally triggered in large crate graphs by functions generated from a proc macro. This may have something to do with weird spans being generated by the proc macro but this is just a guess. I think it's reasonable to land this change since currently, we fail to generate *any* results from llvm-cov when a function has no coverage instrumentation applied to it. With this change, we get coverage data for all functions other than the two cases discussed above.
2022-01-21 01:23:27 +00:00