Skip to content

Commit cce7854

Browse files
committed
Fixed bug for archives
1 parent 366c1f3 commit cce7854

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

lib/src/BitcodeRetriever.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "llvm/Object/MachOUniversal.h"
1111

1212
#include <algorithm>
13+
#include <iostream>
1314
#include <memory>
1415
#include <string>
1516

@@ -55,9 +56,8 @@ std::vector<std::unique_ptr<BitcodeContainer>> BitcodeRetriever::GetBitcodeConta
5556
bitcodeContainers.push_back(std::move(container));
5657
}
5758
continue;
58-
} else {
59-
// Calling operator bool() is not sufficient.
60-
machOObject.takeError();
59+
} else if (auto e = machOObject.takeError()) {
60+
llvm::consumeError(std::move(e));
6161
}
6262

6363
Expected<std::unique_ptr<Archive>> archive = object.getAsArchive();
@@ -67,9 +67,8 @@ std::vector<std::unique_ptr<BitcodeContainer>> BitcodeRetriever::GetBitcodeConta
6767
bitcodeContainers.reserve(bitcodeContainers.size() + containers.size());
6868
std::move(std::begin(containers), std::end(containers), std::back_inserter(bitcodeContainers));
6969
continue;
70-
} else {
71-
// Calling operator bool() is not sufficient.
72-
archive.takeError();
70+
} else if (auto e = archive.takeError()) {
71+
llvm::consumeError(std::move(e));
7372
}
7473

7574
throw EbcError("Unrecognized MachO universal binary");
@@ -99,6 +98,10 @@ std::vector<std::unique_ptr<BitcodeContainer>> BitcodeRetriever::GetBitcodeConta
9998
Error err;
10099
auto children = archive.children(err);
101100

101+
if (err) {
102+
throw EbcError("Couldn't get children from archive " + archive.getFileName().str());
103+
}
104+
102105
auto bitcodeContainers = std::vector<std::unique_ptr<BitcodeContainer>>();
103106
for (const auto &child : children) {
104107
auto childOrErr = child.getAsBinary();

tool/ebcutil.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ int main(int argc, char* argv[]) {
8989
TCLAP::ValueArg<std::string> prefixArg("p", "prefix", "Prefix for bitcode files", false, "", "string");
9090
cmd.add(prefixArg);
9191

92-
TCLAP::UnlabeledValueArg<std::string> fileArg("File", "Library or object file", false, "", "file");
92+
TCLAP::UnlabeledValueArg<std::string> fileArg("File", "Library or object file", true, "", "file");
9393
cmd.add(fileArg);
9494

9595
cmd.parse(argc, argv);

0 commit comments

Comments
 (0)