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 openFile(StringRef Path) { ErrorOr> 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 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 Def = - parseCOFFModuleDefinition(MB, Machine, true); + parseCOFFModuleDefinition(*MB, Machine, true); if (!Def) { llvm::errs() << "error parsing definition\n"