llvm.org GIT mirror llvm / 174360e
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@274106 91177308-0d34-0410-b5e6-96231b3b80d8 Vedant Kumar 4 years ago
2 changed file(s) with 21 addition(s) and 60 deletion(s). Raw diff Collapse all Expand all
2222 namespace llvm {
2323 namespace coverage {
2424
25 /// \brief Writer of the filenames section for the instrumentation
26 /// based code coverage.
27 class CoverageFilenamesSectionWriter {
28 ArrayRef Filenames;
29
30 public:
31 CoverageFilenamesSectionWriter(ArrayRef Filenames)
32 : Filenames(Filenames) {}
33
34 /// \brief Write encoded filenames to the given output stream.
35 void write(raw_ostream &OS);
36 };
37
2538 /// \brief Writer for instrumentation based coverage mapping data.
2639 class CoverageMappingWriter {
2740 ArrayRef VirtualFileMapping;
4356 void write(raw_ostream &OS);
4457 };
4558
46 /// \brief Encode a list of filenames and raw coverage mapping data using the
47 /// latest coverage data format.
48 ///
49 /// Set \p FilenamesSize to the size of the filenames section.
50 ///
51 /// Set \p CoverageMappingsSize to the size of the coverage mapping section
52 /// (including any necessary padding bytes).
53 Expected encodeFilenamesAndRawMappings(
54 ArrayRef Filenames, ArrayRef CoverageMappings,
55 size_t &FilenamesSize, size_t &CoverageMappingsSize);
56
5759 } // end namespace coverage
5860 } // end namespace llvm
5961
1616
1717 using namespace llvm;
1818 using namespace coverage;
19
20 void CoverageFilenamesSectionWriter::write(raw_ostream &OS) {
21 encodeULEB128(Filenames.size(), OS);
22 for (const auto &Filename : Filenames) {
23 encodeULEB128(Filename.size(), OS);
24 OS << Filename;
25 }
26 }
1927
2028 namespace {
2129 /// \brief Gather only the expressions that are used by the mapping
172180 // Ensure that all file ids have at least one mapping region.
173181 assert(CurrentFileID == (VirtualFileMapping.size() - 1));
174182 }
175
176 /// \brief Encode coverage data into \p OS.
177 static void encodeCoverageData(ArrayRef Filenames,
178 ArrayRef CoverageMappings,
179 size_t &FilenamesSize,
180 size_t &CoverageMappingsSize, raw_ostream &OS) {
181 size_t OSOffset = OS.GetNumBytesInBuffer();
182
183 // Encode the filenames.
184 encodeULEB128(Filenames.size(), OS);
185 for (const auto &Filename : Filenames) {
186 encodeULEB128(Filename.size(), OS);
187 OS << Filename;
188 }
189
190 FilenamesSize = OS.GetNumBytesInBuffer() - OSOffset;
191
192 // Encode the coverage mappings.
193 for (const auto &RawMapping : CoverageMappings)
194 OS << RawMapping;
195
196 // Pad the output stream to an 8-byte boundary. Account for the padding bytes
197 // in \p CoverageMappingsSize.
198 if (size_t Rem = OS.GetNumBytesInBuffer() % 8) {
199 CoverageMappingsSize += 8 - Rem;
200 for (size_t I = 0, S = 8 - Rem; I < S; ++I)
201 OS << '\0';
202 }
203
204 CoverageMappingsSize = OS.GetNumBytesInBuffer() - FilenamesSize - OSOffset;
205 }
206
207 namespace llvm {
208 namespace coverage {
209
210 Expected encodeFilenamesAndRawMappings(
211 ArrayRef Filenames, ArrayRef CoverageMappings,
212 size_t &FilenamesSize, size_t &CoverageMappingsSize) {
213 std::string CoverageData;
214 {
215 raw_string_ostream OS{CoverageData};
216 encodeCoverageData(Filenames, CoverageMappings, FilenamesSize,
217 CoverageMappingsSize, OS);
218 }
219 return std::move(CoverageData);
220 }
221
222 } // end namespace coverage
223 } // end namespace llvm