Skip to content

Commit

Permalink
[llvm-size] Make error handling uniform.
Browse files Browse the repository at this point in the history
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@260786 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
dcci committed Feb 13, 2016
1 parent 0bbac93 commit 2ad5a3c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 33 deletions.
2 changes: 1 addition & 1 deletion test/tools/llvm-size/basic.test
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
RUN: llvm-size %t.blah 2>&1 | FileCheck --check-prefix=ENOENT %s
ENOENT: {{.*}}llvm-size{{(\.EXE|\.exe)?}}: {{.*}}.blah: {{[Nn]}}o such file or directory
ENOENT: {{.*}}llvm-size{{(\.EXE|\.exe)?}}: error reading file: {{[Nn]}}o such file or directory
41 changes: 9 additions & 32 deletions tools/llvm-size/llvm-size.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,28 +439,21 @@ static void printFileSectionSizes(StringRef file) {

// Attempt to open the binary.
ErrorOr<OwningBinary<Binary>> BinaryOrErr = createBinary(file);
if (std::error_code EC = BinaryOrErr.getError()) {
errs() << ToolName << ": " << file << ": " << EC.message() << ".\n";
if (error(BinaryOrErr.getError()))
return;
}
Binary &Bin = *BinaryOrErr.get().getBinary();

if (Archive *a = dyn_cast<Archive>(&Bin)) {
// This is an archive. Iterate over each member and display its sizes.
for (object::Archive::child_iterator i = a->child_begin(),
e = a->child_end();
i != e; ++i) {
if (i->getError()) {
errs() << ToolName << ": " << file << ": " << i->getError().message()
<< ".\n";
if (error(i->getError()))
exit(1);
}
auto &c = i->get();
ErrorOr<std::unique_ptr<Binary>> ChildOrErr = c.getAsBinary();
if (std::error_code EC = ChildOrErr.getError()) {
errs() << ToolName << ": " << file << ": " << EC.message() << ".\n";
if (error(ChildOrErr.getError()))
continue;
}
if (ObjectFile *o = dyn_cast<ObjectFile>(&*ChildOrErr.get())) {
MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o);
if (!checkMachOAndArchFlags(o, file))
Expand Down Expand Up @@ -518,18 +511,12 @@ static void printFileSectionSizes(StringRef file) {
for (object::Archive::child_iterator i = UA->child_begin(),
e = UA->child_end();
i != e; ++i) {
if (std::error_code EC = i->getError()) {
errs() << ToolName << ": " << file << ": " << EC.message()
<< ".\n";
if (error(i->getError()))
exit(1);
}
auto &c = i->get();
ErrorOr<std::unique_ptr<Binary>> ChildOrErr = c.getAsBinary();
if (std::error_code EC = ChildOrErr.getError()) {
errs() << ToolName << ": " << file << ": " << EC.message()
<< ".\n";
if (error(ChildOrErr.getError()))
continue;
}
if (ObjectFile *o = dyn_cast<ObjectFile>(&*ChildOrErr.get())) {
MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o);
if (OutputFormat == sysv)
Expand Down Expand Up @@ -601,18 +588,12 @@ static void printFileSectionSizes(StringRef file) {
for (object::Archive::child_iterator i = UA->child_begin(),
e = UA->child_end();
i != e; ++i) {
if (std::error_code EC = i->getError()) {
errs() << ToolName << ": " << file << ": " << EC.message()
<< ".\n";
if (error(i->getError()))
exit(1);
}
auto &c = i->get();
ErrorOr<std::unique_ptr<Binary>> ChildOrErr = c.getAsBinary();
if (std::error_code EC = ChildOrErr.getError()) {
errs() << ToolName << ": " << file << ": " << EC.message()
<< ".\n";
if (error(ChildOrErr.getError()))
continue;
}
if (ObjectFile *o = dyn_cast<ObjectFile>(&*ChildOrErr.get())) {
MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o);
if (OutputFormat == sysv)
Expand Down Expand Up @@ -671,16 +652,12 @@ static void printFileSectionSizes(StringRef file) {
for (object::Archive::child_iterator i = UA->child_begin(),
e = UA->child_end();
i != e; ++i) {
if (std::error_code EC = i->getError()) {
errs() << ToolName << ": " << file << ": " << EC.message() << ".\n";
if (error(i->getError()))
exit(1);
}
auto &c = i->get();
ErrorOr<std::unique_ptr<Binary>> ChildOrErr = c.getAsBinary();
if (std::error_code EC = ChildOrErr.getError()) {
errs() << ToolName << ": " << file << ": " << EC.message() << ".\n";
if (error(ChildOrErr.getError()))
continue;
}
if (ObjectFile *o = dyn_cast<ObjectFile>(&*ChildOrErr.get())) {
MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o);
if (OutputFormat == sysv)
Expand Down

0 comments on commit 2ad5a3c

Please sign in to comment.