From: Vedant Kumar Date: Fri, 17 Jun 2016 21:53:55 +0000 (+0000) Subject: [Coverage] Adopt llvm::coverage::encodeFilenamesAndRawMappings (NFC) X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=161ff9db3a3d0d62880d1cb18d58182cd3034912;p=clang [Coverage] Adopt llvm::coverage::encodeFilenamesAndRawMappings (NFC) Use an llvm helper function to encode filenames and raw mappings. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@273056 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CoverageMappingGen.cpp b/lib/CodeGen/CoverageMappingGen.cpp index 44c90e30cd..12bad4b03f 100644 --- a/lib/CodeGen/CoverageMappingGen.cpp +++ b/lib/CodeGen/CoverageMappingGen.cpp @@ -1008,35 +1008,27 @@ void CoverageMappingModuleGen::emit() { // Create the filenames and merge them with coverage mappings llvm::SmallVector FilenameStrs; - llvm::SmallVector FilenameRefs; FilenameStrs.resize(FileEntries.size()); - FilenameRefs.resize(FileEntries.size()); for (const auto &Entry : FileEntries) { llvm::SmallString<256> Path(Entry.first->getName()); llvm::sys::fs::make_absolute(Path); auto I = Entry.second; FilenameStrs[I] = std::string(Path.begin(), Path.end()); - FilenameRefs[I] = FilenameStrs[I]; } - std::string FilenamesAndCoverageMappings; - llvm::raw_string_ostream OS(FilenamesAndCoverageMappings); - CoverageFilenamesSectionWriter(FilenameRefs).write(OS); - std::string RawCoverageMappings = - llvm::join(CoverageMappings.begin(), CoverageMappings.end(), ""); - OS << RawCoverageMappings; - size_t CoverageMappingSize = RawCoverageMappings.size(); - size_t FilenamesSize = OS.str().size() - CoverageMappingSize; - // Append extra zeroes if necessary to ensure that the size of the filenames - // and coverage mappings is a multiple of 8. - if (size_t Rem = OS.str().size() % 8) { - CoverageMappingSize += 8 - Rem; - for (size_t I = 0, S = 8 - Rem; I < S; ++I) - OS << '\0'; + size_t FilenamesSize; + size_t CoverageMappingSize; + llvm::Expected CoverageDataOrErr = encodeFilenamesAndRawMappings( + FilenameStrs, CoverageMappings, FilenamesSize, CoverageMappingSize); + if (llvm::Error E = CoverageDataOrErr.takeError()) { + llvm::handleAllErrors(std::move(E), [](llvm::ErrorInfoBase &EI) { + llvm::report_fatal_error(EI.message()); + }); } + std::string CoverageData = std::move(CoverageDataOrErr.get()); auto *FilenamesAndMappingsVal = - llvm::ConstantDataArray::getString(Ctx, OS.str(), false); + llvm::ConstantDataArray::getString(Ctx, CoverageData, false); // Create the deferred function records array auto RecordsTy =