From 1d280b012d52fa95ed59942701e1a32c662e58a3 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Sat, 20 Feb 2021 16:43:05 +0100 Subject: Don't directly expose coverage::CounterMappingRegion via FFI The definition of this struct changes in LLVM 12 due to the addition of branch coverage support. To avoid future mismatches, declare our own struct and then convert between them. --- .../llvm-wrapper/CoverageMappingWrapper.cpp | 24 ++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp') diff --git a/compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp index 25badc3f4e1..e97d96e3a4e 100644 --- a/compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp +++ b/compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp @@ -8,6 +8,17 @@ using namespace llvm; +struct LLVMRustCounterMappingRegion { + coverage::Counter Count; + uint32_t FileID; + uint32_t ExpandedFileID; + uint32_t LineStart; + uint32_t ColumnStart; + uint32_t LineEnd; + uint32_t ColumnEnd; + coverage::CounterMappingRegion::RegionKind Kind; +}; + extern "C" void LLVMRustCoverageWriteFilenamesSectionToBuffer( const char* const Filenames[], size_t FilenamesLen, @@ -27,13 +38,22 @@ extern "C" void LLVMRustCoverageWriteMappingToBuffer( unsigned NumVirtualFileMappingIDs, const coverage::CounterExpression *Expressions, unsigned NumExpressions, - coverage::CounterMappingRegion *MappingRegions, + LLVMRustCounterMappingRegion *RustMappingRegions, unsigned NumMappingRegions, RustStringRef BufferOut) { + // Convert from FFI representation to LLVM representation. + SmallVector MappingRegions; + MappingRegions.reserve(NumMappingRegions); + for (const auto &Region : makeArrayRef(RustMappingRegions, NumMappingRegions)) { + MappingRegions.emplace_back( + Region.Count, Region.FileID, Region.ExpandedFileID, + Region.LineStart, Region.ColumnStart, Region.LineEnd, Region.ColumnEnd, + Region.Kind); + } auto CoverageMappingWriter = coverage::CoverageMappingWriter( makeArrayRef(VirtualFileMappingIDs, NumVirtualFileMappingIDs), makeArrayRef(Expressions, NumExpressions), - makeMutableArrayRef(MappingRegions, NumMappingRegions)); + MappingRegions); RawRustStringOstream OS(BufferOut); CoverageMappingWriter.write(OS); } -- cgit 1.4.1-3-g733a5