[PATCH] D36780: [llvm-dlltool] Don't crash if no def file is provided or it can't be opened
Martin Storsjö via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 16 23:00:35 PDT 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL311068: [llvm-dlltool] Don't crash if no def file is provided or it can't be opened (authored by mstorsjo).
Changed prior to commit:
https://reviews.llvm.org/D36780?vs=111305&id=111466#toc
Repository:
rL LLVM
https://reviews.llvm.org/D36780
Files:
llvm/trunk/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp
Index: llvm/trunk/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp
===================================================================
--- llvm/trunk/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp
+++ llvm/trunk/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp
@@ -60,11 +60,13 @@
// Opens a file. Path has to be resolved already.
// Newly created memory buffers are owned by this driver.
-MemoryBufferRef openFile(StringRef Path) {
+Optional<MemoryBufferRef> openFile(StringRef Path) {
ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> MB = MemoryBuffer::getFile(Path);
- if (std::error_code EC = MB.getError())
+ if (std::error_code EC = MB.getError()) {
llvm::errs() << "fail openFile: " << EC.message() << "\n";
+ return None;
+ }
MemoryBufferRef MBRef = MB.get()->getMemBufferRef();
OwningMBs.push_back(std::move(MB.get())); // take ownership
@@ -115,11 +117,16 @@
for (auto *Arg : Args.filtered(OPT_UNKNOWN))
llvm::errs() << "ignoring unknown argument: " << Arg->getSpelling() << "\n";
- MemoryBufferRef MB;
- if (auto *Arg = Args.getLastArg(OPT_d))
- MB = openFile(Arg->getValue());
+ if (!Args.hasArg(OPT_d)) {
+ llvm::errs() << "no definition file specified\n";
+ return 1;
+ }
+
+ Optional<MemoryBufferRef> MB = openFile(Args.getLastArg(OPT_d)->getValue());
+ if (!MB)
+ return 1;
- if (!MB.getBufferSize()) {
+ if (!MB->getBufferSize()) {
llvm::errs() << "definition file empty\n";
return 1;
}
@@ -134,7 +141,7 @@
}
Expected<COFFModuleDefinition> Def =
- parseCOFFModuleDefinition(MB, Machine, true);
+ parseCOFFModuleDefinition(*MB, Machine, true);
if (!Def) {
llvm::errs() << "error parsing definition\n"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36780.111466.patch
Type: text/x-patch
Size: 1710 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170817/6656285e/attachment.bin>
More information about the llvm-commits
mailing list