diff options
| author | Rich Kadel <richkadel@google.com> | 2021-03-15 16:32:45 -0700 |
|---|---|---|
| committer | Rich Kadel <richkadel@google.com> | 2021-03-19 17:11:50 -0700 |
| commit | bcf755562a1e7c2ed4f6a292b3c82afc9b5b5fe6 (patch) | |
| tree | cf808d7ed75963822412132b469384ed3602fdcc /src/test/run-make-fulldeps/coverage-spanview/expected_mir_dump.async/async.j.-------.InstrumentCoverage.0.html | |
| parent | cebc8fef5f4391a9ed8e4c1dc566a6c5824e2901 (diff) | |
| download | rust-bcf755562a1e7c2ed4f6a292b3c82afc9b5b5fe6.tar.gz rust-bcf755562a1e7c2ed4f6a292b3c82afc9b5b5fe6.zip | |
coverage bug fixes and optimization support
Adjusted LLVM codegen for code compiled with `-Zinstrument-coverage` to address multiple, somewhat related issues. Fixed a significant flaw in prior coverage solution: Every counter generated a new counter variable, but there should have only been one counter variable per function. This appears to have bloated .profraw files significantly. (For a small program, it increased the size by about 40%. I have not tested large programs, but there is anecdotal evidence that profraw files were way too large. This is a good fix, regardless, but hopefully it also addresses related issues. Fixes: #82144 Invalid LLVM coverage data produced when compiled with -C opt-level=1 Existing tests now work up to at least `opt-level=3`. This required a detailed analysis of the LLVM IR, comparisons with Clang C++ LLVM IR when compiled with coverage, and a lot of trial and error with codegen adjustments. The biggest hurdle was figuring out how to continue to support coverage results for unused functions and generics. Rust's coverage results have three advantages over Clang's coverage results: 1. Rust's coverage map does not include any overlapping code regions, making coverage counting unambiguous. 2. Rust generates coverage results (showing zero counts) for all unused functions, including generics. (Clang does not generate coverage for uninstantiated template functions.) 3. Rust's unused functions produce minimal stubbed functions in LLVM IR, sufficient for including in the coverage results; while Clang must generate the complete LLVM IR for each unused function, even though it will never be called. This PR removes the previous hack of attempting to inject coverage into some other existing function instance, and generates dedicated instances for each unused function. This change, and a few other adjustments (similar to what is required for `-C link-dead-code`, but with lower impact), makes it possible to support LLVM optimizations. Fixes: #79651 Coverage report: "Unexecuted instantiation:..." for a generic function from multiple crates Fixed by removing the aforementioned hack. Some "Unexecuted instantiation" notices are unavoidable, as explained in the `used_crate.rs` test, but `-Zinstrument-coverage` has new options to back off support for either unused generics, or all unused functions, which avoids the notice, at the cost of less coverage of unused functions. Fixes: #82875 Invalid LLVM coverage data produced with crate brotli_decompressor Fixed by disabling the LLVM function attribute that forces inlining, if `-Z instrument-coverage` is enabled. This attribute is applied to Rust functions with `#[inline(always)], and in some cases, the forced inlining breaks coverage instrumentation and reports.
Diffstat (limited to 'src/test/run-make-fulldeps/coverage-spanview/expected_mir_dump.async/async.j.-------.InstrumentCoverage.0.html')
| -rw-r--r-- | src/test/run-make-fulldeps/coverage-spanview/expected_mir_dump.async/async.j.-------.InstrumentCoverage.0.html | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/src/test/run-make-fulldeps/coverage-spanview/expected_mir_dump.async/async.j.-------.InstrumentCoverage.0.html b/src/test/run-make-fulldeps/coverage-spanview/expected_mir_dump.async/async.j.-------.InstrumentCoverage.0.html index 7cc751074a0..2b43c7bd25d 100644 --- a/src/test/run-make-fulldeps/coverage-spanview/expected_mir_dump.async/async.j.-------.InstrumentCoverage.0.html +++ b/src/test/run-make-fulldeps/coverage-spanview/expected_mir_dump.async/async.j.-------.InstrumentCoverage.0.html @@ -69,7 +69,7 @@ For revisions in Pull Requests (PR): </style> </head> <body> -<div class="code" style="counter-reset: line 48"><span class="line"><span><span class="code even" style="--layer: 1" title="68:11-68:12: @0[0]: FakeRead(ForMatchedPlace, _1)"><span class="annotation">@0,3,4,5⦊</span>fn j(x: u8) {</span></span> +<div class="code" style="counter-reset: line 48"><span class="line"><span><span class="code even" style="--layer: 1" title="68:11-68:12: @0[0]: FakeRead(ForMatchedPlace, _1)"><span class="annotation">@0,3,4⦊</span>fn j(x: u8) {</span></span> <span class="line"><span class="code even" style="--layer: 1" title="68:11-68:12: @0[0]: FakeRead(ForMatchedPlace, _1)"> // non-async versions of `c()`, `d()`, and `f()` to make it similar to async `i()`.</span></span> <span class="line"><span class="code even" style="--layer: 1" title="68:11-68:12: @0[0]: FakeRead(ForMatchedPlace, _1)"> fn c(x: u8) -> u8 {</span></span> <span class="line"><span class="code even" style="--layer: 1" title="68:11-68:12: @0[0]: FakeRead(ForMatchedPlace, _1)"> if x == 8 {</span></span> @@ -88,21 +88,19 @@ For revisions in Pull Requests (PR): <span class="line"><span class="code even" style="--layer: 1" title="68:11-68:12: @0[0]: FakeRead(ForMatchedPlace, _1)"> }</span></span> <span class="line"><span class="code even" style="--layer: 1" title="68:11-68:12: @0[0]: FakeRead(ForMatchedPlace, _1)"> fn d() -> u8 { 1 }</span></span> <span class="line"><span class="code even" style="--layer: 1" title="68:11-68:12: @0[0]: FakeRead(ForMatchedPlace, _1)"> fn f() -> u8 { 1 }</span></span> -<span class="line"><span class="code even" style="--layer: 1" title="68:11-68:12: @0[0]: FakeRead(ForMatchedPlace, _1)"> match x<span class="annotation">⦉@0,3,4,5</span></span></span><span class="code" style="--layer: 0"> {</span></span> -<span class="line"><span class="code" style="--layer: 0"> </span><span><span class="code odd" style="--layer: 1" title="69:9-69:10: @6[3]: _2 = _1"><span class="annotation">@6,8⦊</span>y<span class="annotation">⦉@6,8</span></span></span><span class="code" style="--layer: 0"> if </span><span><span class="code even" style="--layer: 1" title="69:16-69:17: @3[5]: _6 = _1 -69:14-69:18: @3.Call: _5 = j::c(move _6) -> [return: bb4, unwind: bb15] +<span class="line"><span class="code even" style="--layer: 1" title="68:11-68:12: @0[0]: FakeRead(ForMatchedPlace, _1)"> match x<span class="annotation">⦉@0,3,4</span></span></span><span class="code" style="--layer: 0"> {</span></span> +<span class="line"><span class="code" style="--layer: 0"> </span><span><span class="code odd" style="--layer: 1" title="69:9-69:10: @5[3]: _2 = _1"><span class="annotation">@5,7⦊</span>y<span class="annotation">⦉@5,7</span></span></span><span class="code" style="--layer: 0"> if </span><span><span class="code even" style="--layer: 1" title="69:16-69:17: @3[5]: _6 = _1 +69:14-69:18: @3.Call: _5 = j::c(move _6) -> [return: bb4, unwind: bb13] 69:22-69:23: @4[3]: _8 = (*_3) -69:22-69:27: @4[4]: _9 = CheckedAdd(_8, const 1_u8) -69:22-69:27: @5[0]: _7 = move (_9.0: u8) -69:14-69:27: @5[2]: _4 = Eq(move _5, move _7)"><span class="annotation">@0,3,4,5⦊</span>c(x) == y + 1<span class="annotation">⦉@0,3,4,5</span></span></span><span class="code" style="--layer: 0"> => </span><span><span class="code odd" style="--layer: 1" title="69:33-69:36: @6.Call: _10 = j::d() -> [return: bb8, unwind: bb15] -69:31-69:39: @8[1]: _0 = const ()"><span class="annotation">@6,8⦊</span>{ d(); }<span class="annotation">⦉@6,8</span></span></span><span class="code" style="--layer: 0"></span></span> -<span class="line"><span class="code" style="--layer: 0"> </span><span><span class="code even" style="--layer: 1" title="70:9-70:10: @12[3]: _11 = _1"><span class="annotation">@12⦊</span>y<span class="annotation">⦉@12</span></span></span><span class="code" style="--layer: 0"> if </span><span><span class="code odd" style="--layer: 1" title="70:14-70:17: @9.Call: _14 = j::f() -> [return: bb10, unwind: bb15] -70:21-70:22: @10[2]: _16 = (*_12) -70:21-70:26: @10[3]: _17 = CheckedAdd(_16, const 1_u8) -70:21-70:26: @11[0]: _15 = move (_17.0: u8) -70:14-70:26: @11[2]: _13 = Eq(move _14, move _15)"><span class="annotation">@1,9,10,11⦊</span>f() == y + 1<span class="annotation">⦉@1,9,10,11</span></span></span><span class="code" style="--layer: 0"> => </span><span><span class="code even" style="--layer: 1" title="70:30-70:32: @12[4]: _0 = ()"><span class="annotation">@12⦊</span>()<span class="annotation">⦉@12</span></span></span><span class="code" style="--layer: 0">,</span></span> +69:22-69:27: @4[4]: _7 = Add(move _8, const 1_u8) +69:14-69:27: @4[6]: _4 = Eq(move _5, move _7)"><span class="annotation">@0,3,4⦊</span>c(x) == y + 1<span class="annotation">⦉@0,3,4</span></span></span><span class="code" style="--layer: 0"> => </span><span><span class="code odd" style="--layer: 1" title="69:33-69:36: @5.Call: _9 = j::d() -> [return: bb7, unwind: bb13] +69:31-69:39: @7[1]: _0 = const ()"><span class="annotation">@5,7⦊</span>{ d(); }<span class="annotation">⦉@5,7</span></span></span><span class="code" style="--layer: 0"></span></span> +<span class="line"><span class="code" style="--layer: 0"> </span><span><span class="code even" style="--layer: 1" title="70:9-70:10: @10[3]: _10 = _1"><span class="annotation">@10⦊</span>y<span class="annotation">⦉@10</span></span></span><span class="code" style="--layer: 0"> if </span><span><span class="code odd" style="--layer: 1" title="70:14-70:17: @8.Call: _13 = j::f() -> [return: bb9, unwind: bb13] +70:21-70:22: @9[2]: _15 = (*_11) +70:21-70:26: @9[3]: _14 = Add(move _15, const 1_u8) +70:14-70:26: @9[5]: _12 = Eq(move _13, move _14)"><span class="annotation">@1,8,9⦊</span>f() == y + 1<span class="annotation">⦉@1,8,9</span></span></span><span class="code" style="--layer: 0"> => </span><span><span class="code even" style="--layer: 1" title="70:30-70:32: @10[4]: _0 = ()"><span class="annotation">@10⦊</span>()<span class="annotation">⦉@10</span></span></span><span class="code" style="--layer: 0">,</span></span> <span class="line"><span class="code" style="--layer: 0"> _ => </span><span><span class="code odd" style="--layer: 1" title="71:14-71:16: @2[0]: _0 = ()"><span class="annotation">@2⦊</span>()<span class="annotation">⦉@2</span></span></span><span class="code" style="--layer: 0">,</span></span> <span class="line"><span class="code" style="--layer: 0"> }</span></span> -<span class="line"><span class="code" style="--layer: 0">}</span><span><span class="code even" style="--layer: 1" title="73:2-73:2: @14.Return: return"><span class="annotation">@14⦊</span>‸<span class="annotation">⦉@14</span></span></span></span></div> +<span class="line"><span class="code" style="--layer: 0">}</span><span><span class="code even" style="--layer: 1" title="73:2-73:2: @12.Return: return"><span class="annotation">@12⦊</span>‸<span class="annotation">⦉@12</span></span></span></span></div> </body> </html> |
