[llvm] [orc-rt] Add ReportErrorsViaSession utility. (PR #209177)
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 13 06:27:17 PDT 2026
https://github.com/lhames created https://github.com/llvm/llvm-project/pull/209177
ReportErrorsViaSession is a function object constructed from a Session& that forwards Errors to that Session's reportError method. It will be used in upcoming patches to simplify some error reporting plumbing.
>From 0f5b75aca3732f337b12bbe332ddca8419e01d02 Mon Sep 17 00:00:00 2001
From: Lang Hames <lhames at gmail.com>
Date: Mon, 13 Jul 2026 23:17:45 +1000
Subject: [PATCH] [orc-rt] Add ReportErrorsViaSession utility.
ReportErrorsViaSession is a function object constructed from a Session&
that forwards Errors to that Session's reportError method. It will be
used in upcoming patches to simplify some error reporting plumbing.
---
orc-rt/include/orc-rt/Session.h | 11 +++++++++++
orc-rt/test/unit/SessionTest.cpp | 15 +++++++++++++++
2 files changed, 26 insertions(+)
diff --git a/orc-rt/include/orc-rt/Session.h b/orc-rt/include/orc-rt/Session.h
index 7100dfe824672..99b9ec9530b75 100644
--- a/orc-rt/include/orc-rt/Session.h
+++ b/orc-rt/include/orc-rt/Session.h
@@ -527,6 +527,17 @@ class Session {
NotificationService &Notifiers;
};
+/// Helper function object to report errors via the given Session's
+/// reportError method.
+class ReportErrorsViaSession {
+public:
+ explicit ReportErrorsViaSession(Session &S) : S(S) {}
+ void operator()(Error Err) const { S.reportError(std::move(Err)); }
+
+private:
+ Session &S;
+};
+
} // namespace orc_rt
#endif // ORC_RT_SESSION_H
diff --git a/orc-rt/test/unit/SessionTest.cpp b/orc-rt/test/unit/SessionTest.cpp
index 28e4fffca14e8..525230aa677dd 100644
--- a/orc-rt/test/unit/SessionTest.cpp
+++ b/orc-rt/test/unit/SessionTest.cpp
@@ -316,6 +316,21 @@ TEST(SessionTest, ReportError) {
ADD_FAILURE() << "Missing error value";
}
+TEST(SessionTest, ReportErrorsViaSession) {
+ Error E = Error::success();
+ cantFail(std::move(E)); // Force error into checked state.
+
+ // Check that the ReportErrorsViaSession utility works as advertised.
+ Session S(mockExecutorProcessInfo(), noDispatch,
+ [&](Error Err) { E = std::move(Err); });
+ (ReportErrorsViaSession(S))(make_error<StringError>("foo"));
+
+ if (E)
+ EXPECT_EQ(toString(std::move(E)), "foo");
+ else
+ ADD_FAILURE() << "Missing error value";
+}
+
TEST(SessionTest, SingleService) {
size_t OpIdx = 0;
std::optional<size_t> DetachOpIdx;
More information about the llvm-commits
mailing list