diff options
author | Francis Visoiu Mistrih <francisvm@yahoo.com> | 2020-02-24 10:42:21 -0800 |
---|---|---|
committer | Francis Visoiu Mistrih <francisvm@yahoo.com> | 2020-02-24 10:44:42 -0800 |
commit | 7b0a5683fa09be4e60bc93526aad7b63bbca687c (patch) | |
tree | b16e8ab06bc908e4fe1ec3f62abe446eb64ce4ea /llvm/lib/BinaryFormat/MachO.cpp | |
parent | 00570c2f18872ce0a1f68cc73e7e259ad67aa60d (diff) | |
download | llvm-7b0a5683fa09be4e60bc93526aad7b63bbca687c.zip llvm-7b0a5683fa09be4e60bc93526aad7b63bbca687c.tar.gz llvm-7b0a5683fa09be4e60bc93526aad7b63bbca687c.tar.bz2 |
[MachO] Add cpu(sub)type tests and improve error handling
Add checks for triples that don't use mach-o, and unit tests for
everything.
Diffstat (limited to 'llvm/lib/BinaryFormat/MachO.cpp')
-rw-r--r-- | llvm/lib/BinaryFormat/MachO.cpp | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/llvm/lib/BinaryFormat/MachO.cpp b/llvm/lib/BinaryFormat/MachO.cpp index bb5ec36..2b9eb80 100644 --- a/llvm/lib/BinaryFormat/MachO.cpp +++ b/llvm/lib/BinaryFormat/MachO.cpp @@ -68,7 +68,15 @@ static MachO::CPUSubTypePowerPC getPowerPCSubType(const Triple &T) { return MachO::CPU_SUBTYPE_POWERPC_ALL; } +static Error unsupported(const char *Str, const Triple &T) { + return createStringError(std::errc::invalid_argument, + "Unsupported triple for mach-o cpu %s: %s", Str, + T.str().c_str()); +} + Expected<uint32_t> MachO::getCPUType(const Triple &T) { + if (!T.isOSBinFormatMachO()) + return unsupported("type", T); if (T.isX86() && T.isArch32Bit()) return MachO::CPU_TYPE_X86; if (T.isX86() && T.isArch64Bit()) @@ -83,11 +91,12 @@ Expected<uint32_t> MachO::getCPUType(const Triple &T) { return MachO::CPU_TYPE_POWERPC; if (T.getArch() == Triple::ppc64) return MachO::CPU_TYPE_POWERPC64; - return createStringError(std::errc::invalid_argument, - "Unsupported triple for mach-o cpu type."); + return unsupported("type", T); } Expected<uint32_t> MachO::getCPUSubType(const Triple &T) { + if (!T.isOSBinFormatMachO()) + return unsupported("subtype", T); if (T.isX86()) return getX86SubType(T); if (T.isARM() || T.isThumb()) @@ -96,6 +105,5 @@ Expected<uint32_t> MachO::getCPUSubType(const Triple &T) { return getARM64SubType(T); if (T.getArch() == Triple::ppc || T.getArch() == Triple::ppc64) return getPowerPCSubType(T); - return createStringError(std::errc::invalid_argument, - "Unsupported triple for mach-o cpu subtype."); + return unsupported("subtype", T); } |