Skip to content

Commit 5c5cd19

Browse files
committed
mcdc-coverage: Add FFI for getting Bitmap IPSK, Bump CoverageMappingVersion
1 parent 1782978 commit 5c5cd19

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ use rustc_span::Symbol;
3131
pub fn finalize(cx: &CodegenCx<'_, '_>) {
3232
let tcx = cx.tcx;
3333

34-
// Ensure the installed version of LLVM supports Coverage Map Version 6
35-
// (encoded as a zero-based value: 5), which was introduced with LLVM 13.
34+
// Ensure the installed version of LLVM supports Coverage Map Version 7
35+
// (encoded as a zero-based value: 6), which was introduced with LLVM 13.
3636
let version = coverageinfo::mapping_version();
37-
assert_eq!(version, 5, "The `CoverageMappingVersion` exposed by `llvm-wrapper` is out of sync");
37+
assert_eq!(version, 6, "The `CoverageMappingVersion` exposed by `llvm-wrapper` is out of sync");
3838

3939
debug!("Generating coverage map for CodegenUnit: `{}`", cx.codegen_unit.name());
4040

@@ -276,6 +276,7 @@ fn encode_mappings_for_function(
276276
/// Construct coverage map header and the array of function records, and combine them into the
277277
/// coverage map. Save the coverage map data into the LLVM IR as a static global using a
278278
/// specific, well-known section and name.
279+
/// https://llvm.org/docs/CoverageMappingFormat.html#llvm-ir-representation
279280
fn generate_coverage_map<'ll>(
280281
cx: &CodegenCx<'ll, '_>,
281282
version: u32,

compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,3 +278,13 @@ pub(crate) fn covfun_section_name(cx: &CodegenCx<'_, '_>) -> String {
278278
})
279279
.expect("Rust Coverage function record section name failed UTF-8 conversion")
280280
}
281+
282+
/// Returns the section name for the MC/DC Bitmap section passed to the linker.
283+
/// FIXME: Remove allow deadcode
284+
#[allow(dead_code)]
285+
pub(crate) fn prf_bits_section_name(cx: &CodegenCx<'_, '_>) -> String {
286+
llvm::build_string(|s| unsafe {
287+
llvm::LLVMRustCoverageWriteBitmapSectionNameToString(cx.llmod, s);
288+
})
289+
.expect("Rust Coverage function record section name failed UTF-8 conversion")
290+
}

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1788,6 +1788,9 @@ extern "C" {
17881788
#[allow(improper_ctypes)]
17891789
pub fn LLVMRustCoverageWriteFuncSectionNameToString(M: &Module, Str: &RustString);
17901790

1791+
#[allow(improper_ctypes)]
1792+
pub fn LLVMRustCoverageWriteBitmapSectionNameToString(M: &Module, Str: &RustString);
1793+
17911794
#[allow(improper_ctypes)]
17921795
pub fn LLVMRustCoverageWriteMappingVarNameToString(Str: &RustString);
17931796

compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,17 @@ extern "C" void LLVMRustCoverageWriteFuncSectionNameToString(LLVMModuleRef M,
204204
WriteSectionNameToString(M, IPSK_covfun, Str);
205205
}
206206

207+
extern "C" void LLVMRustCoverageWriteBitmapSectionNameToString(LLVMModuleRef M,
208+
RustStringRef Str) {
209+
WriteSectionNameToString(M, IPSK_bitmap, Str);
210+
}
211+
207212
extern "C" void LLVMRustCoverageWriteMappingVarNameToString(RustStringRef Str) {
208213
auto name = getCoverageMappingVarName();
209214
auto OS = RawRustStringOstream(Str);
210215
OS << name;
211216
}
212217

213218
extern "C" uint32_t LLVMRustCoverageMappingVersion() {
214-
return coverage::CovMapVersion::Version6;
219+
return coverage::CovMapVersion::Version7;
215220
}

0 commit comments

Comments
 (0)