[llvm] [opt] Properly report errors when loading pass plugins (PR #69745)
Arthur Eubanks via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 20 11:01:25 PDT 2023
https://github.com/aeubanks created https://github.com/llvm/llvm-project/pull/69745
All error messages here already contain the path to the plugin, so no need to repeat it in opt.cpp.
>From 77bed0f2c776985f9a98623e27466aaf9b745f50 Mon Sep 17 00:00:00 2001
From: Arthur Eubanks <aeubanks at google.com>
Date: Fri, 20 Oct 2023 10:57:38 -0700
Subject: [PATCH] [opt] Properly report errors when loading pass plugins
All error messages here already contain the path to the plugin, so no need to repeat it in opt.cpp.
---
llvm/test/Feature/load_plugin_error.ll | 5 +++++
llvm/tools/opt/opt.cpp | 8 +++-----
2 files changed, 8 insertions(+), 5 deletions(-)
create mode 100644 llvm/test/Feature/load_plugin_error.ll
diff --git a/llvm/test/Feature/load_plugin_error.ll b/llvm/test/Feature/load_plugin_error.ll
new file mode 100644
index 000000000000000..24a7cce5d8d397e
--- /dev/null
+++ b/llvm/test/Feature/load_plugin_error.ll
@@ -0,0 +1,5 @@
+; REQUIRES: plugins, examples
+; UNSUPPORTED: target={{.*windows.*}}
+
+; RUN: not opt < %s -load-pass-plugin=%t/nonexistant.so -disable-output 2>&1 | FileCheck %s
+; CHECK: Could not load library {{.*}}nonexistant.so
diff --git a/llvm/tools/opt/opt.cpp b/llvm/tools/opt/opt.cpp
index ed9c10d971218f1..44e74742fd4c82a 100644
--- a/llvm/tools/opt/opt.cpp
+++ b/llvm/tools/opt/opt.cpp
@@ -39,6 +39,7 @@
#include "llvm/Passes/PassPlugin.h"
#include "llvm/Remarks/HotnessThresholdParser.h"
#include "llvm/Support/Debug.h"
+#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/PluginLoader.h"
@@ -441,11 +442,8 @@ int main(int argc, char **argv) {
SmallVector<PassPlugin, 1> PluginList;
PassPlugins.setCallback([&](const std::string &PluginPath) {
auto Plugin = PassPlugin::Load(PluginPath);
- if (!Plugin) {
- errs() << "Failed to load passes from '" << PluginPath
- << "'. Request ignored.\n";
- return;
- }
+ if (!Plugin)
+ report_fatal_error(Plugin.takeError(), /*gen_crash_diag=*/false);
PluginList.emplace_back(Plugin.get());
});
More information about the llvm-commits
mailing list