[llvm] 43db72d - ForceFunctionAttrs: Use reportFatalUsageError (#139473)

via llvm-commits llvm-commits at lists.llvm.org
Thu May 15 06:00:10 PDT 2025


Author: Matt Arsenault
Date: 2025-05-15T15:00:05+02:00
New Revision: 43db72d56d6491e5b826172f9dea706aec92693c

URL: https://github.com/llvm/llvm-project/commit/43db72d56d6491e5b826172f9dea706aec92693c
DIFF: https://github.com/llvm/llvm-project/commit/43db72d56d6491e5b826172f9dea706aec92693c.diff

LOG: ForceFunctionAttrs: Use reportFatalUsageError (#139473)

Added: 
    llvm/test/Transforms/ForcedFunctionAttrs/open-file-error.ll

Modified: 
    llvm/lib/Transforms/IPO/ForceFunctionAttrs.cpp

Removed: 
    


################################################################################
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
+}


        


More information about the llvm-commits mailing list