From 044eb2f6afba375a914ac9d8024f8f5142bb912e Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Mon, 18 Dec 2017 20:10:56 +0000 Subject: Vendor import of llvm trunk r321017: https://llvm.org/svn/llvm-project/llvm/trunk@321017 --- lib/ProfileData/Coverage/CoverageMappingReader.cpp | 41 +++++++++++++--------- 1 file changed, 25 insertions(+), 16 deletions(-) (limited to 'lib/ProfileData/Coverage/CoverageMappingReader.cpp') diff --git a/lib/ProfileData/Coverage/CoverageMappingReader.cpp b/lib/ProfileData/Coverage/CoverageMappingReader.cpp index fff0a03ccbe01..649cf507357ef 100644 --- a/lib/ProfileData/Coverage/CoverageMappingReader.cpp +++ b/lib/ProfileData/Coverage/CoverageMappingReader.cpp @@ -20,7 +20,6 @@ #include "llvm/ADT/StringRef.h" #include "llvm/ADT/Triple.h" #include "llvm/Object/Binary.h" -#include "llvm/Object/COFF.h" #include "llvm/Object/Error.h" #include "llvm/Object/MachOUniversal.h" #include "llvm/Object/ObjectFile.h" @@ -33,13 +32,6 @@ #include "llvm/Support/LEB128.h" #include "llvm/Support/MathExtras.h" #include "llvm/Support/raw_ostream.h" -#include -#include -#include -#include -#include -#include -#include #include using namespace llvm; @@ -49,16 +41,18 @@ using namespace object; #define DEBUG_TYPE "coverage-mapping" void CoverageMappingIterator::increment() { + if (ReadErr != coveragemap_error::success) + return; + // Check if all the records were read or if an error occurred while reading // the next record. - if (auto E = Reader->readNextRecord(Record)) { + if (auto E = Reader->readNextRecord(Record)) handleAllErrors(std::move(E), [&](const CoverageMapError &CME) { if (CME.get() == coveragemap_error::eof) *this = CoverageMappingIterator(); else - llvm_unreachable("Unexpected error in coverage mapping iterator"); + ReadErr = CME.get(); }); - } } Error RawCoverageReader::readULEB128(uint64_t &Result) { @@ -214,6 +208,13 @@ Error RawCoverageMappingReader::readMappingRegionsSubArray( if (auto Err = readIntMax(ColumnEnd, std::numeric_limits::max())) return Err; LineStart += LineStartDelta; + + // If the high bit of ColumnEnd is set, this is a gap region. + if (ColumnEnd & (1U << 31)) { + Kind = CounterMappingRegion::GapRegion; + ColumnEnd &= ~(1U << 31); + } + // Adjust the column locations for the empty regions that are supposed to // cover whole lines. Those regions should be encoded with the // column range (1 -> std::numeric_limits::max()), but because @@ -238,9 +239,12 @@ Error RawCoverageMappingReader::readMappingRegionsSubArray( dbgs() << "\n"; }); - MappingRegions.push_back(CounterMappingRegion( - C, InferredFileID, ExpandedFileID, LineStart, ColumnStart, - LineStart + NumLines, ColumnEnd, Kind)); + auto CMR = CounterMappingRegion(C, InferredFileID, ExpandedFileID, + LineStart, ColumnStart, + LineStart + NumLines, ColumnEnd, Kind); + if (CMR.startLoc() > CMR.endLoc()) + return make_error(coveragemap_error::malformed); + MappingRegions.push_back(CMR); } return Error::success(); } @@ -529,11 +533,16 @@ Expected> CovMapFuncRecordReader::get( return llvm::make_unique>(P, R, F); case CovMapVersion::Version2: + case CovMapVersion::Version3: // Decompress the name data. if (Error E = P.create(P.getNameData())) return std::move(E); - return llvm::make_unique>(P, R, F); + if (Version == CovMapVersion::Version2) + return llvm::make_unique>(P, R, F); + else + return llvm::make_unique>(P, R, F); } llvm_unreachable("Unsupported version"); } -- cgit v1.2.3