[llvm] 7fafaa0 - [llvm-cov] Warn when -arch spec is missing/invalid for universal binary (reland)
Vedant Kumar via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 13 16:46:14 PDT 2020
Author: Vedant Kumar
Date: 2020-10-13T16:46:03-07:00
New Revision: 7fafaa07bcaddd6cad8323940b73c0df98a8f02a
URL: https://github.com/llvm/llvm-project/commit/7fafaa07bcaddd6cad8323940b73c0df98a8f02a
DIFF: https://github.com/llvm/llvm-project/commit/7fafaa07bcaddd6cad8323940b73c0df98a8f02a.diff
LOG: [llvm-cov] Warn when -arch spec is missing/invalid for universal binary (reland)
llvm-cov reports a poor error message when the -arch specifier is
missing or invalid, and a binary has multiple slices. Make the error
message more specific.
(This version of the patch avoids using llvm::none_of -- the way I used
the utility caused compile errors on many bots, possibly because the
wrong overload of `none_of` was selected.)
rdar://40312677
Added:
Modified:
llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
llvm/test/tools/llvm-cov/universal-binary.c
Removed:
################################################################################
diff --git a/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h b/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
index bf0dffc9653c..2f285bf54a6a 100644
--- a/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
+++ b/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
@@ -55,7 +55,8 @@ enum class coveragemap_error {
unsupported_version,
truncated,
malformed,
- decompression_failed
+ decompression_failed,
+ invalid_or_missing_arch_specifier
};
const std::error_category &coveragemap_category();
diff --git a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
index ec840a3f628e..87dab212bdcd 100644
--- a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
+++ b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
@@ -816,6 +816,8 @@ static std::string getCoverageMapErrString(coveragemap_error Err) {
return "Malformed coverage data";
case coveragemap_error::decompression_failed:
return "Failed to decompress coverage data (zlib)";
+ case coveragemap_error::invalid_or_missing_arch_specifier:
+ return "`-arch` specifier is invalid or missing for universal binary";
}
llvm_unreachable("A value of coveragemap_error has no message.");
}
diff --git a/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp b/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
index b75738bc360c..4936638c61cc 100644
--- a/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
+++ b/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
@@ -950,6 +950,19 @@ loadBinaryFormat(std::unique_ptr<Binary> Bin, StringRef Arch) {
BytesInAddress, Endian);
}
+/// Determine whether \p Arch is invalid or empty, given \p Bin.
+static bool isArchSpecifierInvalidOrMissing(Binary *Bin, StringRef Arch) {
+ // If we have a universal binary and Arch doesn't identify any of its slices,
+ // it's user error.
+ if (auto *Universal = dyn_cast<MachOUniversalBinary>(Bin)) {
+ for (auto &ObjForArch : Universal->objects())
+ if (Arch == ObjForArch.getArchFlagName())
+ return false;
+ return true;
+ }
+ return false;
+}
+
Expected<std::vector<std::unique_ptr<BinaryCoverageReader>>>
BinaryCoverageReader::create(
MemoryBufferRef ObjectBuffer, StringRef Arch,
@@ -970,6 +983,10 @@ BinaryCoverageReader::create(
return BinOrErr.takeError();
std::unique_ptr<Binary> Bin = std::move(BinOrErr.get());
+ if (isArchSpecifierInvalidOrMissing(Bin.get(), Arch))
+ return make_error<CoverageMapError>(
+ coveragemap_error::invalid_or_missing_arch_specifier);
+
// MachO universal binaries which contain archives need to be treated as
// archives, not as regular binaries.
if (auto *Universal = dyn_cast<MachOUniversalBinary>(Bin.get())) {
diff --git a/llvm/test/tools/llvm-cov/universal-binary.c b/llvm/test/tools/llvm-cov/universal-binary.c
index 635cd32146eb..f8d5346bc579 100644
--- a/llvm/test/tools/llvm-cov/universal-binary.c
+++ b/llvm/test/tools/llvm-cov/universal-binary.c
@@ -10,8 +10,9 @@ int main(int argc, const char *argv[]) {}
// COMBINED: showTemplateInstantiations.cpp
// COMBINED-NEXT: universal-binary.c
+// RUN: not llvm-cov show %S/Inputs/universal-binary -instr-profile %t.profdata -path-equivalence=/tmp,%S %s 2>&1 | FileCheck --check-prefix=WRONG-ARCH %s
// RUN: not llvm-cov show %S/Inputs/universal-binary -instr-profile %t.profdata -path-equivalence=/tmp,%S %s -arch i386 2>&1 | FileCheck --check-prefix=WRONG-ARCH %s
-// WRONG-ARCH: Failed to load coverage
+// WRONG-ARCH: Failed to load coverage: `-arch` specifier is invalid or missing for universal binary
// RUN: not llvm-cov show %S/Inputs/universal-binary -instr-profile %t.profdata -path-equivalence=/tmp,%S %s -arch definitly_a_made_up_architecture 2>&1 | FileCheck --check-prefix=MADE-UP-ARCH %s
// MADE-UP-ARCH: Unknown architecture: definitly_a_made_up_architecture
More information about the llvm-commits
mailing list