Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Merged

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
Copy link
Contributor

@fhahn fhahn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks

if (!BufferOrError) {
std::error_code EC = BufferOrError.getError();
M.getContext().emitError("cannot open CSV file: " + EC.message());
return PreservedAnalyses::all();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The whole flag seems a bit unusual to me, would it make more sense to just continue w/o the file if it doesn't exist after printing an error?

@arsenm arsenm merged commit 43db72d into main May 15, 2025
11 checks passed
@arsenm arsenm deleted the users/arsenm/force-function-attrs/use-reportFatalUsageError branch May 15, 2025 13:00
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.

3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.