<< Counter::EncodingTagBits;
/// \brief Read the sub-array of regions for the given inferred file id.
-/// \param NumFileIDs: the number of file ids that are defined for this
+/// \param NumFileIDs the number of file ids that are defined for this
/// function.
std::error_code RawCoverageMappingReader::readMappingRegionsSubArray(
std::vector<CounterMappingRegion> &MappingRegions, unsigned InferredFileID,
case CounterMappingRegion::CodeRegion:
// Don't do anything when we have a code region with a zero counter.
break;
- case CounterMappingRegion::EmptyRegion:
- Kind = CounterMappingRegion::EmptyRegion;
- break;
case CounterMappingRegion::SkippedRegion:
Kind = CounterMappingRegion::SkippedRegion;
break;
}
// Read the source range.
- uint64_t LineStartDelta, ColumnStart, NumLines, ColumnEnd;
+ uint64_t LineStartDelta, CodeBeforeColumnStart, NumLines, ColumnEnd;
if (auto Err =
readIntMax(LineStartDelta, std::numeric_limits<unsigned>::max()))
return Err;
- if (auto Err =
- readIntMax(ColumnStart, std::numeric_limits<unsigned>::max()))
+ if (auto Err = readULEB128(CodeBeforeColumnStart))
return Err;
+ bool HasCodeBefore = CodeBeforeColumnStart & 1;
+ uint64_t ColumnStart = CodeBeforeColumnStart >>
+ CounterMappingRegion::EncodingHasCodeBeforeBits;
+ if (ColumnStart > std::numeric_limits<unsigned>::max())
+ return error(instrprof_error::malformed);
if (auto Err = readIntMax(NumLines, std::numeric_limits<unsigned>::max()))
return Err;
if (auto Err = readIntMax(ColumnEnd, std::numeric_limits<unsigned>::max()))
ColumnStart = 1;
ColumnEnd = std::numeric_limits<unsigned>::max();
}
- MappingRegions.push_back(
- CounterMappingRegion(C, InferredFileID, LineStart, ColumnStart,
- LineStart + NumLines, ColumnEnd, Kind));
+ MappingRegions.push_back(CounterMappingRegion(
+ C, InferredFileID, LineStart, ColumnStart, LineStart + NumLines,
+ ColumnEnd, HasCodeBefore, Kind));
MappingRegions.back().ExpandedFileID = ExpandedFileID;
}
return success();
// from the expanded file.
// Perform multiple passes to correctly propagate the counters through
// all the nested expansion regions.
+ SmallVector<CounterMappingRegion *, 8> FileIDExpansionRegionMapping;
+ FileIDExpansionRegionMapping.resize(VirtualFileMapping.size(), nullptr);
for (unsigned Pass = 1, S = VirtualFileMapping.size(); Pass < S; ++Pass) {
- for (auto &I : MappingRegions) {
- if (I.Kind == CounterMappingRegion::ExpansionRegion) {
- for (const auto &J : MappingRegions) {
- if (J.FileID == I.ExpandedFileID) {
- I.Count = J.Count;
- break;
- }
- }
+ for (auto &R : MappingRegions) {
+ if (R.Kind != CounterMappingRegion::ExpansionRegion)
+ continue;
+ assert(!FileIDExpansionRegionMapping[R.ExpandedFileID]);
+ FileIDExpansionRegionMapping[R.ExpandedFileID] = &R;
+ }
+ for (auto &R : MappingRegions) {
+ if (FileIDExpansionRegionMapping[R.FileID]) {
+ FileIDExpansionRegionMapping[R.FileID]->Count = R.Count;
+ FileIDExpansionRegionMapping[R.FileID] = nullptr;
}
}
}
if (!File)
error(File.getError());
else
- Object.reset(File.get());
+ Object = std::move(File.get());
}
ObjectFileCoverageMappingReader::ObjectFileCoverageMappingReader(
if (!File)
error(File.getError());
else
- Object.reset(File.get());
+ Object = std::move(File.get());
}
namespace {