aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
diff options
context:
space:
mode:
authorDaniel Thornburgh <dthorn@google.com>2023-02-17 13:43:57 -0800
committerDaniel Thornburgh <dthorn@google.com>2023-03-03 10:24:21 -0800
commit072e07a9d5928fd3b1c1dabeac82890713ce172b (patch)
tree3940c80f7e2b9c98029d81a4a0a1a9b241644d45 /llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
parent3ac8d322100bc72aaacb67f13eb21d9b644f9930 (diff)
downloadllvm-072e07a9d5928fd3b1c1dabeac82890713ce172b.zip
llvm-072e07a9d5928fd3b1c1dabeac82890713ce172b.tar.gz
llvm-072e07a9d5928fd3b1c1dabeac82890713ce172b.tar.bz2
[llvm-cov] Optionally fail on missing binary ID
This adds the --check-binary-id flag that makes sure that an object file is available for every binary ID mentioned in the given profile. This should help make the tool more robust in CI environments where it's expected that coverage mappings should be available for every object contributing to the profile. Reviewed By: gulfem Differential Revision: https://reviews.llvm.org/D144308
Diffstat (limited to 'llvm/lib/ProfileData/Coverage/CoverageMapping.cpp')
-rw-r--r--llvm/lib/ProfileData/Coverage/CoverageMapping.cpp31
1 files changed, 19 insertions, 12 deletions
diff --git a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
index 360d30d..d6aec27 100644
--- a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
+++ b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
@@ -15,7 +15,9 @@
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallBitVector.h"
+#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Object/BuildID.h"
#include "llvm/ProfileData/Coverage/CoverageMappingReader.h"
@@ -382,11 +384,10 @@ Error CoverageMapping::loadFromFile(
return Error::success();
}
-Expected<std::unique_ptr<CoverageMapping>>
-CoverageMapping::load(ArrayRef<StringRef> ObjectFilenames,
- StringRef ProfileFilename, vfs::FileSystem &FS,
- ArrayRef<StringRef> Arches, StringRef CompilationDir,
- const object::BuildIDFetcher *BIDFetcher) {
+Expected<std::unique_ptr<CoverageMapping>> CoverageMapping::load(
+ ArrayRef<StringRef> ObjectFilenames, StringRef ProfileFilename,
+ vfs::FileSystem &FS, ArrayRef<StringRef> Arches, StringRef CompilationDir,
+ const object::BuildIDFetcher *BIDFetcher, bool CheckBinaryIDs) {
auto ProfileReaderOrErr = IndexedInstrProfReader::create(ProfileFilename, FS);
if (Error E = ProfileReaderOrErr.takeError())
return createFileError(ProfileFilename, std::move(E));
@@ -430,13 +431,19 @@ CoverageMapping::load(ArrayRef<StringRef> ObjectFilenames,
for (object::BuildIDRef BinaryID : BinaryIDsToFetch) {
std::optional<std::string> PathOpt = BIDFetcher->fetch(BinaryID);
- if (!PathOpt)
- continue;
- std::string Path = std::move(*PathOpt);
- StringRef Arch = Arches.size() == 1 ? Arches.front() : StringRef();
- if (Error E = loadFromFile(Path, Arch, CompilationDir, *ProfileReader,
- *Coverage, DataFound))
- return std::move(E);
+ if (PathOpt) {
+ std::string Path = std::move(*PathOpt);
+ StringRef Arch = Arches.size() == 1 ? Arches.front() : StringRef();
+ if (Error E = loadFromFile(Path, Arch, CompilationDir, *ProfileReader,
+ *Coverage, DataFound))
+ return std::move(E);
+ } else if (CheckBinaryIDs) {
+ return createFileError(
+ ProfileFilename,
+ createStringError(errc::no_such_file_or_directory,
+ "Missing binary ID: " +
+ llvm::toHex(BinaryID, /*LowerCase=*/true)));
+ }
}
}