diff --git a/llvm/lib/Transforms/IPO/ForceFunctionAttrs.cpp b/llvm/lib/Transforms/IPO/ForceFunctionAttrs.cpp index 9cf4e448c9b6f..7ea7937d8b827 100644 --- a/llvm/lib/Transforms/IPO/ForceFunctionAttrs.cpp +++ b/llvm/lib/Transforms/IPO/ForceFunctionAttrs.cpp @@ -91,8 +91,12 @@ PreservedAnalyses ForceFunctionAttrsPass::run(Module &M, bool Changed = false; if (!CSVFilePath.empty()) { auto BufferOrError = MemoryBuffer::getFileOrSTDIN(CSVFilePath); - if (!BufferOrError) - report_fatal_error("Cannot open CSV file."); + if (!BufferOrError) { + std::error_code EC = BufferOrError.getError(); + M.getContext().emitError("cannot open CSV file: " + EC.message()); + return PreservedAnalyses::all(); + } + StringRef Buffer = BufferOrError.get()->getBuffer(); auto MemoryBuffer = MemoryBuffer::getMemBuffer(Buffer); line_iterator It(*MemoryBuffer); diff --git a/llvm/test/Transforms/ForcedFunctionAttrs/open-file-error.ll b/llvm/test/Transforms/ForcedFunctionAttrs/open-file-error.ll new file mode 100644 index 0000000000000..61db001d7eb1e --- /dev/null +++ b/llvm/test/Transforms/ForcedFunctionAttrs/open-file-error.ll @@ -0,0 +1,6 @@ +; RUN: not opt -disable-output -passes='forceattrs' -forceattrs-csv-path="%S/CannotOpenFile.csv" %s 2>&1 | FileCheck -DMSG=%errc_ENOENT %s + +; CHECK: error: cannot open CSV file: [[MSG]] +define void @first_function() { + ret void +}