mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-26 04:32:44 +01:00
[llvm-cov] Warn when -arch spec is missing/invalid for universal binary
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. rdar://40312677
This commit is contained in:
parent
bfbf8b669b
commit
40fbc09049
@ -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();
|
||||
|
@ -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.");
|
||||
}
|
||||
|
@ -950,6 +950,18 @@ 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))
|
||||
return none_of(Universal->objects(),
|
||||
[Arch](const MachOUniversalBinary::ObjectForArch &Obj) {
|
||||
return Obj.getArchFlagName() == Arch;
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
Expected<std::vector<std::unique_ptr<BinaryCoverageReader>>>
|
||||
BinaryCoverageReader::create(
|
||||
MemoryBufferRef ObjectBuffer, StringRef Arch,
|
||||
@ -970,6 +982,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())) {
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user