coverage: Add LLVM plumbing for expansion regions

This is currently unused, but paves the way for future work on expansion
regions without having to worry about the FFI parts.
This commit is contained in:
Zalathar 2025-03-04 21:55:43 +11:00
parent 2947be7af8
commit d07ef5b0e1
5 changed files with 57 additions and 7 deletions

View file

@ -77,6 +77,13 @@ struct LLVMRustCoverageCodeRegion {
LLVMRustCounter Count;
};
// Must match the layout of
// `rustc_codegen_llvm::coverageinfo::ffi::ExpansionRegion`.
struct LLVMRustCoverageExpansionRegion {
LLVMRustCoverageSpan Span;
uint32_t ExpandedFileID;
};
// Must match the layout of
// `rustc_codegen_llvm::coverageinfo::ffi::BranchRegion`.
struct LLVMRustCoverageBranchRegion {
@ -151,6 +158,8 @@ extern "C" void LLVMRustCoverageWriteFunctionMappingsToBuffer(
const unsigned *VirtualFileMappingIDs, size_t NumVirtualFileMappingIDs,
const LLVMRustCounterExpression *RustExpressions, size_t NumExpressions,
const LLVMRustCoverageCodeRegion *CodeRegions, size_t NumCodeRegions,
const LLVMRustCoverageExpansionRegion *ExpansionRegions,
size_t NumExpansionRegions,
const LLVMRustCoverageBranchRegion *BranchRegions, size_t NumBranchRegions,
const LLVMRustCoverageMCDCBranchRegion *MCDCBranchRegions,
size_t NumMCDCBranchRegions,
@ -179,6 +188,13 @@ extern "C" void LLVMRustCoverageWriteFunctionMappingsToBuffer(
Region.Span.ColumnStart, Region.Span.LineEnd, Region.Span.ColumnEnd));
}
// Expansion regions:
for (const auto &Region : ArrayRef(ExpansionRegions, NumExpansionRegions)) {
MappingRegions.push_back(coverage::CounterMappingRegion::makeExpansion(
Region.Span.FileID, Region.ExpandedFileID, Region.Span.LineStart,
Region.Span.ColumnStart, Region.Span.LineEnd, Region.Span.ColumnEnd));
}
// Branch regions:
for (const auto &Region : ArrayRef(BranchRegions, NumBranchRegions)) {
MappingRegions.push_back(coverage::CounterMappingRegion::makeBranchRegion(