[PATCH] D156611: [llvm-cov] Fix a bug about using `convert-for-testing` on multi-source object files
Gulfem Savrun Yeniceri via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 14 19:52:21 PDT 2023
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf8ad86c23405: [llvm-cov] Fix a bug about using `convert-for-testing` on multi-source object… (authored by AtomicGu, committed by gulfem).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D156611/new/
https://reviews.llvm.org/D156611
Files:
llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
llvm/test/tools/llvm-cov/Inputs/combine_expansions.covmapping
llvm/test/tools/llvm-cov/Inputs/compilation_dir.covmapping
llvm/test/tools/llvm-cov/Inputs/coverage_prefix_map/main.covmapping
llvm/test/tools/llvm-cov/Inputs/deferred-regions.covmapping
llvm/test/tools/llvm-cov/Inputs/dir-with-filtering.covmapping
llvm/test/tools/llvm-cov/Inputs/double_dots.covmapping
llvm/test/tools/llvm-cov/Inputs/highlightedRanges.covmapping
llvm/test/tools/llvm-cov/Inputs/ifdef.covmapping
llvm/test/tools/llvm-cov/Inputs/lineExecutionCounts.covmapping
llvm/test/tools/llvm-cov/Inputs/malformedRegions.covmapping
llvm/test/tools/llvm-cov/Inputs/multiple-files.covmapping
llvm/test/tools/llvm-cov/Inputs/multiple-files2.covmapping
llvm/test/tools/llvm-cov/Inputs/multiple_objects/use_1.covmapping
llvm/test/tools/llvm-cov/Inputs/multiple_objects/use_2.covmapping
llvm/test/tools/llvm-cov/Inputs/multithreaded_report/main.covmapping
llvm/test/tools/llvm-cov/Inputs/name_allowlist.covmapping
llvm/test/tools/llvm-cov/Inputs/name_whitelist.covmapping
llvm/test/tools/llvm-cov/Inputs/native_separators.covmapping
llvm/test/tools/llvm-cov/Inputs/path_equivalence.covmapping
llvm/test/tools/llvm-cov/Inputs/prefer_used_to_unused.covmapping
llvm/test/tools/llvm-cov/Inputs/prevent_false_instantiations.covmapping
llvm/test/tools/llvm-cov/Inputs/regionMarkers.covmapping
llvm/test/tools/llvm-cov/Inputs/relative_dir/main.covmapping
llvm/test/tools/llvm-cov/Inputs/report.covmapping
llvm/test/tools/llvm-cov/Inputs/showExpansions.covmapping
llvm/test/tools/llvm-cov/Inputs/showProjectSummary.covmapping
llvm/test/tools/llvm-cov/Inputs/showTabsHTML.covmapping
llvm/test/tools/llvm-cov/Inputs/sources_specified/main.covmapping
llvm/test/tools/llvm-cov/Inputs/templateInstantiations.covmapping
llvm/test/tools/llvm-cov/Inputs/zeroFunctionFile.covmapping
llvm/tools/llvm-cov/TestingSupport.cpp
Index: llvm/tools/llvm-cov/TestingSupport.cpp
===================================================================
--- llvm/tools/llvm-cov/TestingSupport.cpp
+++ llvm/tools/llvm-cov/TestingSupport.cpp
@@ -111,6 +111,7 @@
encodeULEB128(ProfileNamesData.size(), OS);
encodeULEB128(ProfileNamesAddress, OS);
OS << ProfileNamesData;
+ encodeULEB128(CoverageMappingData.size(), OS);
// Coverage mapping data is expected to have an alignment of 8.
for (unsigned Pad = offsetToAlignment(OS.tell(), Align(8)); Pad; --Pad)
OS.write(uint8_t(0));
Index: llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
===================================================================
--- llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
+++ llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
@@ -886,41 +886,46 @@
if (Error E = ProfileNames.create(Data.substr(0, ProfileNamesSize), Address))
return std::move(E);
Data = Data.substr(ProfileNamesSize);
+
+ N = 0;
+ uint64_t CoverageMappingSize = decodeULEB128(Data.bytes_begin(), &N);
+ if (N > Data.size())
+ return make_error<CoverageMapError>(coveragemap_error::malformed);
+ Data = Data.substr(N);
+
// Skip the padding bytes because coverage map data has an alignment of 8.
size_t Pad = offsetToAlignedAddr(Data.data(), Align(8));
if (Data.size() < Pad)
return make_error<CoverageMapError>(coveragemap_error::malformed);
Data = Data.substr(Pad);
- if (Data.size() < sizeof(CovMapHeader))
+ if (Data.size() < CoverageMappingSize)
+ return make_error<CoverageMapError>(coveragemap_error::malformed);
+ StringRef CoverageMapping = Data.substr(0, CoverageMappingSize);
+ Data = Data.substr(CoverageMappingSize);
+
+ // Skip the padding bytes because coverage records data has an alignment of 8.
+ Pad = offsetToAlignedAddr(Data.data(), Align(8));
+ if (Data.size() < Pad)
return make_error<CoverageMapError>(coveragemap_error::malformed);
- auto const *CovHeader = reinterpret_cast<const CovMapHeader *>(
- Data.substr(0, sizeof(CovMapHeader)).data());
+ Data = Data.substr(Pad);
+ BinaryCoverageReader::FuncRecordsStorage CoverageRecords =
+ MemoryBuffer::getMemBuffer(Data);
+
+ // Some extra checking.
+ if (CoverageMapping.size() < sizeof(CovMapHeader))
+ return make_error<CoverageMapError>(coveragemap_error::truncated);
+ auto const *CovHeader =
+ reinterpret_cast<const CovMapHeader *>(CoverageMapping.data());
CovMapVersion Version =
(CovMapVersion)CovHeader->getVersion<support::endianness::little>();
- StringRef CoverageMapping;
- BinaryCoverageReader::FuncRecordsStorage CoverageRecords;
if (Version < CovMapVersion::Version4) {
- CoverageMapping = Data;
- if (CoverageMapping.empty())
- return make_error<CoverageMapError>(coveragemap_error::truncated);
- CoverageRecords = MemoryBuffer::getMemBuffer("");
- } else {
- uint32_t FilenamesSize =
- CovHeader->getFilenamesSize<support::endianness::little>();
- uint32_t CoverageMappingSize = sizeof(CovMapHeader) + FilenamesSize;
- CoverageMapping = Data.substr(0, CoverageMappingSize);
- if (CoverageMapping.empty())
- return make_error<CoverageMapError>(coveragemap_error::truncated);
- Data = Data.substr(CoverageMappingSize);
- // Skip the padding bytes because coverage records data has an alignment
- // of 8.
- Pad = offsetToAlignedAddr(Data.data(), Align(8));
- if (Data.size() < Pad)
+ if (CoverageRecords->getBufferSize() != 0)
return make_error<CoverageMapError>(coveragemap_error::malformed);
- CoverageRecords = MemoryBuffer::getMemBuffer(Data.substr(Pad));
+ } else {
if (CoverageRecords->getBufferSize() == 0)
return make_error<CoverageMapError>(coveragemap_error::truncated);
}
+
return BinaryCoverageReader::createCoverageReaderFromBuffer(
CoverageMapping, std::move(CoverageRecords), std::move(ProfileNames),
BytesInAddress, Endian, CompilationDir);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156611.550177.patch
Type: text/x-patch
Size: 3983 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230815/18db169f/attachment.bin>
More information about the llvm-commits
mailing list