Skip to content

Commit aa3900d

Browse files
committed
mcdc-coverage: Add FFI for getting Bitmap IPSK, Bump CoverageMappingVersion
1 parent 561a56e commit aa3900d

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
@@ -32,10 +32,10 @@ use rustc_span::Symbol;
3232
pub fn finalize(cx: &CodegenCx<'_, '_>) {
3333
let tcx = cx.tcx;
3434

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

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

@@ -271,6 +271,7 @@ fn encode_mappings_for_function(
271271
/// Construct coverage map header and the array of function records, and combine them into the
272272
/// coverage map. Save the coverage map data into the LLVM IR as a static global using a
273273
/// specific, well-known section and name.
274+
/// https://llvm.org/docs/CoverageMappingFormat.html#llvm-ir-representation
274275
fn generate_coverage_map<'ll>(
275276
cx: &CodegenCx<'ll, '_>,
276277
version: u32,

compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs

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

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)