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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions llvm/lib/Transforms/IPO/ForceFunctionAttrs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
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?

}

StringRef Buffer = BufferOrError.get()->getBuffer();
auto MemoryBuffer = MemoryBuffer::getMemBuffer(Buffer);
line_iterator It(*MemoryBuffer);
Expand Down
6 changes: 6 additions & 0 deletions llvm/test/Transforms/ForcedFunctionAttrs/open-file-error.ll
Original file line number Diff line number Diff line change
@@ -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
}