diff options
| author | Rich Kadel <richkadel@google.com> | 2020-07-24 21:14:28 -0700 |
|---|---|---|
| committer | Rich Kadel <richkadel@google.com> | 2020-07-25 07:39:51 -0700 |
| commit | 12ddd6073abecb7a515a43bee37408596e322345 (patch) | |
| tree | b7f3eaf24fe718c9b55581732a545ecd971021a3 /src/rustllvm/CoverageMappingWrapper.cpp | |
| parent | c4e173472beb073ce3759525a15ed429b032787a (diff) | |
| download | rust-12ddd6073abecb7a515a43bee37408596e322345.tar.gz rust-12ddd6073abecb7a515a43bee37408596e322345.zip | |
Fixed coverage map issues; better aligned with LLVM APIs
Found some problems with the coverage map encoding when testing with more than one counter per function. While debugging, I realized some better ways to structure the Rust implementation of the coverage mapping generator. I refactored somewhat, resulting in less code overall, expanded coverage of LLVM Coverage Map capabilities, and much closer alignment with LLVM data structures, APIs, and naming. This should be easier to follow and easier to maintain.
Diffstat (limited to 'src/rustllvm/CoverageMappingWrapper.cpp')
| -rw-r--r-- | src/rustllvm/CoverageMappingWrapper.cpp | 66 |
1 files changed, 7 insertions, 59 deletions
diff --git a/src/rustllvm/CoverageMappingWrapper.cpp b/src/rustllvm/CoverageMappingWrapper.cpp index c6c4cdb5562..7c8481540aa 100644 --- a/src/rustllvm/CoverageMappingWrapper.cpp +++ b/src/rustllvm/CoverageMappingWrapper.cpp @@ -8,60 +8,6 @@ using namespace llvm; -extern "C" SmallVectorTemplateBase<coverage::CounterExpression> - *LLVMRustCoverageSmallVectorCounterExpressionCreate() { - return new SmallVector<coverage::CounterExpression, 32>(); -} - -extern "C" void LLVMRustCoverageSmallVectorCounterExpressionDispose( - SmallVectorTemplateBase<coverage::CounterExpression> *Vector) { - delete Vector; -} - -extern "C" void LLVMRustCoverageSmallVectorCounterExpressionAdd( - SmallVectorTemplateBase<coverage::CounterExpression> *Expressions, - coverage::CounterExpression::ExprKind Kind, - unsigned LeftIndex, - unsigned RightIndex) { - auto LHS = coverage::Counter::getCounter(LeftIndex); - auto RHS = coverage::Counter::getCounter(RightIndex); - Expressions->push_back(coverage::CounterExpression { Kind, LHS, RHS }); -} - -extern "C" SmallVectorTemplateBase<coverage::CounterMappingRegion> - *LLVMRustCoverageSmallVectorCounterMappingRegionCreate() { - return new SmallVector<coverage::CounterMappingRegion, 32>(); -} - -extern "C" void LLVMRustCoverageSmallVectorCounterMappingRegionDispose( - SmallVectorTemplateBase<coverage::CounterMappingRegion> *Vector) { - delete Vector; -} - -extern "C" void LLVMRustCoverageSmallVectorCounterMappingRegionAdd( - SmallVectorTemplateBase<coverage::CounterMappingRegion> *MappingRegions, - unsigned Index, - unsigned FileID, - unsigned LineStart, - unsigned ColumnStart, - unsigned LineEnd, - unsigned ColumnEnd) { - auto Counter = coverage::Counter::getCounter(Index); - MappingRegions->push_back(coverage::CounterMappingRegion::makeRegion( - Counter, FileID, LineStart, - ColumnStart, LineEnd, ColumnEnd)); - - // FIXME(richkadel): As applicable, implement additional CounterMappingRegion types using the - // static method alternatives to `coverage::CounterMappingRegion::makeRegion`: - // - // makeExpansion(unsigned FileID, unsigned ExpandedFileID, unsigned LineStart, - // unsigned ColumnStart, unsigned LineEnd, unsigned ColumnEnd) { - // makeSkipped(unsigned FileID, unsigned LineStart, unsigned ColumnStart, - // unsigned LineEnd, unsigned ColumnEnd) { - // makeGapRegion(Counter Count, unsigned FileID, unsigned LineStart, - // unsigned ColumnStart, unsigned LineEnd, unsigned ColumnEnd) { -} - extern "C" void LLVMRustCoverageWriteFilenamesSectionToBuffer( const char* const Filenames[], size_t FilenamesLen, @@ -79,13 +25,15 @@ extern "C" void LLVMRustCoverageWriteFilenamesSectionToBuffer( extern "C" void LLVMRustCoverageWriteMappingToBuffer( const unsigned *VirtualFileMappingIDs, unsigned NumVirtualFileMappingIDs, - const SmallVectorImpl<coverage::CounterExpression> *Expressions, - SmallVectorImpl<coverage::CounterMappingRegion> *MappingRegions, + const coverage::CounterExpression *Expressions, + unsigned NumExpressions, + coverage::CounterMappingRegion *MappingRegions, + unsigned NumMappingRegions, RustStringRef BufferOut) { auto CoverageMappingWriter = coverage::CoverageMappingWriter( - makeArrayRef(VirtualFileMappingIDs, NumVirtualFileMappingIDs), - makeArrayRef(*Expressions), - MutableArrayRef<coverage::CounterMappingRegion> { *MappingRegions }); + makeArrayRef(VirtualFileMappingIDs, NumVirtualFileMappingIDs), + makeArrayRef(Expressions, NumExpressions), + makeMutableArrayRef(MappingRegions, NumMappingRegions)); RawRustStringOstream OS(BufferOut); CoverageMappingWriter.write(OS); } |
