Fix an unconditional break in checkMachOAndArchFlags

Found by PVS-Studio.

llvm-svn: 285598
This commit is contained in:
David Majnemer 2016-10-31 17:11:31 +00:00
parent f5c0689e92
commit 91160d851e
3 changed files with 44 additions and 52 deletions

View File

@ -1051,9 +1051,9 @@ dumpSymbolNamesFromObject(SymbolicFile &Obj, bool printName,
// architectures was specificed. If not then an error is generated and this // architectures was specificed. If not then an error is generated and this
// routine returns false. Else it returns true. // routine returns false. Else it returns true.
static bool checkMachOAndArchFlags(SymbolicFile *O, std::string &Filename) { static bool checkMachOAndArchFlags(SymbolicFile *O, std::string &Filename) {
MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(O); auto *MachO = dyn_cast<MachOObjectFile>(O);
if (!MachO || ArchAll || ArchFlags.size() == 0) if (!MachO || ArchAll || ArchFlags.empty())
return true; return true;
MachO::mach_header H; MachO::mach_header H;

View File

@ -1186,30 +1186,26 @@ static void DumpInfoPlistSectionContents(StringRef Filename,
// architectures were specified. If not then an error is generated and this // architectures were specified. If not then an error is generated and this
// routine returns false. Else it returns true. // routine returns false. Else it returns true.
static bool checkMachOAndArchFlags(ObjectFile *O, StringRef Filename) { static bool checkMachOAndArchFlags(ObjectFile *O, StringRef Filename) {
if (isa<MachOObjectFile>(O) && !ArchAll && ArchFlags.size() != 0) { auto *MachO = dyn_cast<MachOObjectFile>(O);
MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(O);
bool ArchFound = false; if (!MachO || ArchAll || ArchFlags.empty())
MachO::mach_header H; return true;
MachO::mach_header_64 H_64;
Triple T; MachO::mach_header H;
if (MachO->is64Bit()) { MachO::mach_header_64 H_64;
H_64 = MachO->MachOObjectFile::getHeader64(); Triple T;
T = MachOObjectFile::getArchTriple(H_64.cputype, H_64.cpusubtype); if (MachO->is64Bit()) {
} else { H_64 = MachO->MachOObjectFile::getHeader64();
H = MachO->MachOObjectFile::getHeader(); T = MachOObjectFile::getArchTriple(H_64.cputype, H_64.cpusubtype);
T = MachOObjectFile::getArchTriple(H.cputype, H.cpusubtype); } else {
} H = MachO->MachOObjectFile::getHeader();
unsigned i; T = MachOObjectFile::getArchTriple(H.cputype, H.cpusubtype);
for (i = 0; i < ArchFlags.size(); ++i) { }
if (ArchFlags[i] == T.getArchName()) if (none_of(ArchFlags, [&](const std::string &Name) {
ArchFound = true; return Name == T.getArchName();
break; })) {
} errs() << "llvm-objdump: " + Filename + ": No architecture specified.\n";
if (!ArchFound) { return false;
errs() << "llvm-objdump: file: " + Filename + " does not contain "
<< "architecture: " + ArchFlags[i] + "\n";
return false;
}
} }
return true; return true;
} }

View File

@ -498,36 +498,32 @@ static void printObjectSectionSizes(ObjectFile *Obj) {
} }
} }
/// Checks to see if the @p o ObjectFile is a Mach-O file and if it is and there /// Checks to see if the @p O ObjectFile is a Mach-O file and if it is and there
/// is a list of architecture flags specified then check to make sure this /// is a list of architecture flags specified then check to make sure this
/// Mach-O file is one of those architectures or all architectures was /// Mach-O file is one of those architectures or all architectures was
/// specificed. If not then an error is generated and this routine returns /// specificed. If not then an error is generated and this routine returns
/// false. Else it returns true. /// false. Else it returns true.
static bool checkMachOAndArchFlags(ObjectFile *o, StringRef file) { static bool checkMachOAndArchFlags(ObjectFile *O, StringRef Filename) {
if (isa<MachOObjectFile>(o) && !ArchAll && ArchFlags.size() != 0) { auto *MachO = dyn_cast<MachOObjectFile>(O);
MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o);
bool ArchFound = false; if (!MachO || ArchAll || ArchFlags.empty())
MachO::mach_header H; return true;
MachO::mach_header_64 H_64;
Triple T; MachO::mach_header H;
if (MachO->is64Bit()) { MachO::mach_header_64 H_64;
H_64 = MachO->MachOObjectFile::getHeader64(); Triple T;
T = MachOObjectFile::getArchTriple(H_64.cputype, H_64.cpusubtype); if (MachO->is64Bit()) {
} else { H_64 = MachO->MachOObjectFile::getHeader64();
H = MachO->MachOObjectFile::getHeader(); T = MachOObjectFile::getArchTriple(H_64.cputype, H_64.cpusubtype);
T = MachOObjectFile::getArchTriple(H.cputype, H.cpusubtype); } else {
} H = MachO->MachOObjectFile::getHeader();
unsigned i; T = MachOObjectFile::getArchTriple(H.cputype, H.cpusubtype);
for (i = 0; i < ArchFlags.size(); ++i) { }
if (ArchFlags[i] == T.getArchName()) if (none_of(ArchFlags, [&](const std::string &Name) {
ArchFound = true; return Name == T.getArchName();
break; })) {
} error(Filename + ": No architecture specified");
if (!ArchFound) { return false;
errs() << ToolName << ": file: " << file
<< " does not contain architecture: " << ArchFlags[i] << ".\n";
return false;
}
} }
return true; return true;
} }