[llvm] ForceFunctionAttrs: Use reportFatalUsageError (PR #139473)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Sun May 11 14:09:10 PDT 2025
https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/139473
>From 6051017294763a9116786ffb21dba32126ae8874 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Sun, 11 May 2025 22:55:57 +0200
Subject: [PATCH] ForceFunctionAttrs: Avoid report_fatal_error
Report error in context with the error code. Also add
a missing test for the failure.
---
llvm/lib/Transforms/IPO/ForceFunctionAttrs.cpp | 8 ++++++--
.../Transforms/ForcedFunctionAttrs/open-file-error.ll | 6 ++++++
2 files changed, 12 insertions(+), 2 deletions(-)
create mode 100644 llvm/test/Transforms/ForcedFunctionAttrs/open-file-error.ll
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