Skip to content

ForceFunctionAttrs: Use reportFatalUsageError #139473

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

arsenm
Copy link
Contributor

@arsenm arsenm commented May 11, 2025

Also add a missing test for the failure.

@arsenm arsenm marked this pull request as ready for review May 11, 2025 21:02
Copy link
Contributor Author

arsenm commented May 11, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

@llvmbot
Copy link
Member

llvmbot commented May 11, 2025

@llvm/pr-subscribers-llvm-transforms

Author: Matt Arsenault (arsenm)

Changes

Also add a missing test for the failure.


Full diff: https://github.com/llvm/llvm-project/pull/139473.diff

2 Files Affected:

  • (modified) llvm/lib/Transforms/IPO/ForceFunctionAttrs.cpp (+1-1)
  • (added) llvm/test/Transforms/ForcedFunctionAttrs/open-file-error.ll (+6)
diff --git a/llvm/lib/Transforms/IPO/ForceFunctionAttrs.cpp b/llvm/lib/Transforms/IPO/ForceFunctionAttrs.cpp
index 9cf4e448c9b6f..5b4d3b7c1be7e 100644
--- a/llvm/lib/Transforms/IPO/ForceFunctionAttrs.cpp
+++ b/llvm/lib/Transforms/IPO/ForceFunctionAttrs.cpp
@@ -92,7 +92,7 @@ PreservedAnalyses ForceFunctionAttrsPass::run(Module &M,
   if (!CSVFilePath.empty()) {
     auto BufferOrError = MemoryBuffer::getFileOrSTDIN(CSVFilePath);
     if (!BufferOrError)
-      report_fatal_error("Cannot open CSV file.");
+      reportFatalUsageError("cannot open CSV file");
     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..2eded57651616
--- /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 %s
+
+; CHECK: LLVM ERROR: cannot open CSV file
+define void @first_function() {
+  ret void
+}

Report error in context with the error code. Also add
a missing test for the failure.
@arsenm arsenm force-pushed the users/arsenm/force-function-attrs/use-reportFatalUsageError branch from df88f43 to 6051017 Compare May 11, 2025 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants