diff --git a/llvm/test/tools/llvm-dis/errors.test b/llvm/test/tools/llvm-dis/errors.test new file mode 100644 --- /dev/null +++ b/llvm/test/tools/llvm-dis/errors.test @@ -0,0 +1,3 @@ +# RUN: not llvm-dis missing-file-path 2>&1 | FileCheck %s --check-prefix=MISSING + +# MISSING: error: missing-file-path: No such file or directory diff --git a/llvm/tools/llvm-dis/llvm-dis.cpp b/llvm/tools/llvm-dis/llvm-dis.cpp --- a/llvm/tools/llvm-dis/llvm-dis.cpp +++ b/llvm/tools/llvm-dis/llvm-dis.cpp @@ -180,8 +180,13 @@ } for (std::string InputFilename : InputFilenames) { - std::unique_ptr MB = ExitOnErr( - errorOrToExpected(MemoryBuffer::getFileOrSTDIN(InputFilename))); + ErrorOr> BufferOrErr = + MemoryBuffer::getFileOrSTDIN(InputFilename); + if (std::error_code EC = BufferOrErr.getError()) { + WithColor::error() << InputFilename << ": " << EC.message() << '\n'; + return 1; + } + std::unique_ptr MB = std::move(BufferOrErr.get()); BitcodeFileContents IF = ExitOnErr(llvm::getBitcodeFileContents(*MB));