ForceFunctionAttrs: Use reportFatalUsageError (#139473)
diff --git a/llvm/lib/Transforms/IPO/ForceFunctionAttrs.cpp b/llvm/lib/Transforms/IPO/ForceFunctionAttrs.cpp
index 9cf4e44..7ea7937 100644
--- a/llvm/lib/Transforms/IPO/ForceFunctionAttrs.cpp
+++ b/llvm/lib/Transforms/IPO/ForceFunctionAttrs.cpp
@@ -91,8 +91,12 @@
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 0000000..61db001
--- /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
+}