forked from OSchip/llvm-project
Revert "[Coverage] Move logic to encode filenames and mappings into llvm (NFC)"
This reverts commit 520a8298d8ef676b5da617ba3d2c7fa37381e939 (r273055). This is breaking stage2 instrumented builds with "malformed coverage data" errors. llvm-svn: 274106
This commit is contained in:
parent
a30139d50c
commit
34e4e477c8
|
@ -23,6 +23,19 @@
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
namespace coverage {
|
namespace coverage {
|
||||||
|
|
||||||
|
/// \brief Writer of the filenames section for the instrumentation
|
||||||
|
/// based code coverage.
|
||||||
|
class CoverageFilenamesSectionWriter {
|
||||||
|
ArrayRef<StringRef> Filenames;
|
||||||
|
|
||||||
|
public:
|
||||||
|
CoverageFilenamesSectionWriter(ArrayRef<StringRef> Filenames)
|
||||||
|
: Filenames(Filenames) {}
|
||||||
|
|
||||||
|
/// \brief Write encoded filenames to the given output stream.
|
||||||
|
void write(raw_ostream &OS);
|
||||||
|
};
|
||||||
|
|
||||||
/// \brief Writer for instrumentation based coverage mapping data.
|
/// \brief Writer for instrumentation based coverage mapping data.
|
||||||
class CoverageMappingWriter {
|
class CoverageMappingWriter {
|
||||||
ArrayRef<unsigned> VirtualFileMapping;
|
ArrayRef<unsigned> VirtualFileMapping;
|
||||||
|
@ -44,17 +57,6 @@ public:
|
||||||
void write(raw_ostream &OS);
|
void write(raw_ostream &OS);
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \brief Encode a list of filenames and raw coverage mapping data using the
|
|
||||||
/// latest coverage data format.
|
|
||||||
///
|
|
||||||
/// Set \p FilenamesSize to the size of the filenames section.
|
|
||||||
///
|
|
||||||
/// Set \p CoverageMappingsSize to the size of the coverage mapping section
|
|
||||||
/// (including any necessary padding bytes).
|
|
||||||
Expected<std::string> encodeFilenamesAndRawMappings(
|
|
||||||
ArrayRef<std::string> Filenames, ArrayRef<std::string> CoverageMappings,
|
|
||||||
size_t &FilenamesSize, size_t &CoverageMappingsSize);
|
|
||||||
|
|
||||||
} // end namespace coverage
|
} // end namespace coverage
|
||||||
} // end namespace llvm
|
} // end namespace llvm
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,14 @@
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
using namespace coverage;
|
using namespace coverage;
|
||||||
|
|
||||||
|
void CoverageFilenamesSectionWriter::write(raw_ostream &OS) {
|
||||||
|
encodeULEB128(Filenames.size(), OS);
|
||||||
|
for (const auto &Filename : Filenames) {
|
||||||
|
encodeULEB128(Filename.size(), OS);
|
||||||
|
OS << Filename;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
/// \brief Gather only the expressions that are used by the mapping
|
/// \brief Gather only the expressions that are used by the mapping
|
||||||
/// regions in this function.
|
/// regions in this function.
|
||||||
|
@ -173,52 +181,3 @@ void CoverageMappingWriter::write(raw_ostream &OS) {
|
||||||
// Ensure that all file ids have at least one mapping region.
|
// Ensure that all file ids have at least one mapping region.
|
||||||
assert(CurrentFileID == (VirtualFileMapping.size() - 1));
|
assert(CurrentFileID == (VirtualFileMapping.size() - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \brief Encode coverage data into \p OS.
|
|
||||||
static void encodeCoverageData(ArrayRef<std::string> Filenames,
|
|
||||||
ArrayRef<std::string> CoverageMappings,
|
|
||||||
size_t &FilenamesSize,
|
|
||||||
size_t &CoverageMappingsSize, raw_ostream &OS) {
|
|
||||||
size_t OSOffset = OS.GetNumBytesInBuffer();
|
|
||||||
|
|
||||||
// Encode the filenames.
|
|
||||||
encodeULEB128(Filenames.size(), OS);
|
|
||||||
for (const auto &Filename : Filenames) {
|
|
||||||
encodeULEB128(Filename.size(), OS);
|
|
||||||
OS << Filename;
|
|
||||||
}
|
|
||||||
|
|
||||||
FilenamesSize = OS.GetNumBytesInBuffer() - OSOffset;
|
|
||||||
|
|
||||||
// Encode the coverage mappings.
|
|
||||||
for (const auto &RawMapping : CoverageMappings)
|
|
||||||
OS << RawMapping;
|
|
||||||
|
|
||||||
// Pad the output stream to an 8-byte boundary. Account for the padding bytes
|
|
||||||
// in \p CoverageMappingsSize.
|
|
||||||
if (size_t Rem = OS.GetNumBytesInBuffer() % 8) {
|
|
||||||
CoverageMappingsSize += 8 - Rem;
|
|
||||||
for (size_t I = 0, S = 8 - Rem; I < S; ++I)
|
|
||||||
OS << '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
CoverageMappingsSize = OS.GetNumBytesInBuffer() - FilenamesSize - OSOffset;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace llvm {
|
|
||||||
namespace coverage {
|
|
||||||
|
|
||||||
Expected<std::string> encodeFilenamesAndRawMappings(
|
|
||||||
ArrayRef<std::string> Filenames, ArrayRef<std::string> CoverageMappings,
|
|
||||||
size_t &FilenamesSize, size_t &CoverageMappingsSize) {
|
|
||||||
std::string CoverageData;
|
|
||||||
{
|
|
||||||
raw_string_ostream OS{CoverageData};
|
|
||||||
encodeCoverageData(Filenames, CoverageMappings, FilenamesSize,
|
|
||||||
CoverageMappingsSize, OS);
|
|
||||||
}
|
|
||||||
return std::move(CoverageData);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // end namespace coverage
|
|
||||||
} // end namespace llvm
|
|
||||||
|
|
Loading…
Reference in New Issue