about summary refs log tree commit diff
path: root/src/librustc_codegen_llvm/base.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-07-19 07:25:18 +0000
committerbors <bors@rust-lang.org>2020-07-19 07:25:18 +0000
commit47ea6d90b073ab977cf072e2f5f46d63de532cc6 (patch)
treed408537bbf5d8d3063d19914f6e30efe02c74681 /src/librustc_codegen_llvm/base.rs
parent0701419e96d94e5493c7ebfcecb66511ab0aa778 (diff)
parenta6f8b8a2116f0ea7e31d572d3120508678ed8079 (diff)
downloadrust-47ea6d90b073ab977cf072e2f5f46d63de532cc6.tar.gz
rust-47ea6d90b073ab977cf072e2f5f46d63de532cc6.zip
Auto merge of #74091 - richkadel:llvm-coverage-map-gen-4, r=tmandry
Generating the coverage map

@tmandry @wesleywiser

rustc now generates the coverage map and can support (limited)
coverage report generation, at the function level.

Example commands to generate a coverage report:
```shell
$ BUILD=$HOME/rust/build/x86_64-unknown-linux-gnu
$ $BUILD/stage1/bin/rustc -Zinstrument-coverage \
$HOME/rust/src/test/run-make-fulldeps/instrument-coverage/main.rs
$ LLVM_PROFILE_FILE="main.profraw" ./main
called
$ $BUILD/llvm/bin/llvm-profdata merge -sparse main.profraw -o main.profdata
$ $BUILD/llvm/bin/llvm-cov show --instr-profile=main.profdata main
```
![rust coverage report only 20200706](https://user-images.githubusercontent.com/3827298/86697299-1cbe8f80-bfc3-11ea-8955-451b48626991.png)

r? @wesleywiser

Rust compiler MCP rust-lang/compiler-team#278
Relevant issue: #34701 - Implement support for LLVMs code coverage instrumentation
Diffstat (limited to 'src/librustc_codegen_llvm/base.rs')
-rw-r--r--src/librustc_codegen_llvm/base.rs11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/librustc_codegen_llvm/base.rs b/src/librustc_codegen_llvm/base.rs
index d5e0d7d36ee..b19199b9cfa 100644
--- a/src/librustc_codegen_llvm/base.rs
+++ b/src/librustc_codegen_llvm/base.rs
@@ -144,17 +144,18 @@ pub fn compile_codegen_unit(
                 }
             }
 
+            // Finalize code coverage by injecting the coverage map. Note, the coverage map will
+            // also be added to the `llvm.used` variable, created next.
+            if cx.sess().opts.debugging_opts.instrument_coverage {
+                cx.coverageinfo_finalize();
+            }
+
             // Create the llvm.used variable
             // This variable has type [N x i8*] and is stored in the llvm.metadata section
             if !cx.used_statics().borrow().is_empty() {
                 cx.create_used_variable()
             }
 
-            // Finalize code coverage by injecting the coverage map
-            if cx.sess().opts.debugging_opts.instrument_coverage {
-                cx.coverageinfo_finalize();
-            }
-
             // Finalize debuginfo
             if cx.sess().opts.debuginfo != DebugInfo::None {
                 cx.debuginfo_finalize();