[llvm] r311068 - [llvm-dlltool] Don't crash if no def file is provided or it can't be opened
Hans Wennborg via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 17 10:16:08 PDT 2017
Merged to 5.0 in r311104.
On Wed, Aug 16, 2017 at 10:58 PM, Martin Storsjo via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
> Author: mstorsjo
> Date: Wed Aug 16 22:58:27 2017
> New Revision: 311068
>
> URL: http://llvm.org/viewvc/llvm-project?rev=311068&view=rev
> Log:
> [llvm-dlltool] Don't crash if no def file is provided or it can't be opened
>
> Differential Revision: https://reviews.llvm.org/D36780
>
> Modified:
> llvm/trunk/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp
>
> Modified: llvm/trunk/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp?rev=311068&r1=311067&r2=311068&view=diff
> ==============================================================================
> --- llvm/trunk/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp (original)
> +++ llvm/trunk/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp Wed Aug 16 22:58:27 2017
> @@ -60,11 +60,13 @@ std::vector<std::unique_ptr<MemoryBuffer
>
> // 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 @@ int llvm::dlltoolDriverMain(llvm::ArrayR
> 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 @@ int llvm::dlltoolDriverMain(llvm::ArrayR
> }
>
> Expected<COFFModuleDefinition> Def =
> - parseCOFFModuleDefinition(MB, Machine, true);
> + parseCOFFModuleDefinition(*MB, Machine, true);
>
> if (!Def) {
> llvm::errs() << "error parsing definition\n"
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list