[llvm] 8abf46d - [ORC] Propagate out-of-band errors in callAsync.

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 11 14:24:04 PDT 2021


Author: Lang Hames
Date: 2021-10-11T14:23:50-07:00
New Revision: 8abf46d39a0cf93d0299ea31426a566747064f69

URL: https://github.com/llvm/llvm-project/commit/8abf46d39a0cf93d0299ea31426a566747064f69
DIFF: https://github.com/llvm/llvm-project/commit/8abf46d39a0cf93d0299ea31426a566747064f69.diff

LOG: [ORC] Propagate out-of-band errors in callAsync.

Returned out-of-band errors should be wrapped as llvm::Errors and passed to the
SendDeserializedResult function. Failure to do this results in an assertion when
we try to deserialize from the WrapperFunctionResult while it's in the
out-of-band error state.

Added: 
    

Modified: 
    llvm/include/llvm/ExecutionEngine/Orc/Shared/WrapperFunctionUtils.h
    llvm/unittests/ExecutionEngine/Orc/WrapperFunctionUtilsTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ExecutionEngine/Orc/Shared/WrapperFunctionUtils.h b/llvm/include/llvm/ExecutionEngine/Orc/Shared/WrapperFunctionUtils.h
index 0dd581b45d8d6..b1ca1f10097b2 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/Shared/WrapperFunctionUtils.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/Shared/WrapperFunctionUtils.h
@@ -492,6 +492,12 @@ class WrapperFunction<SPSRetTagT(SPSTagTs...)> {
       RetT RetVal = detail::ResultDeserializer<SPSRetTagT, RetT>::makeValue();
       detail::ResultDeserializer<SPSRetTagT, RetT>::makeSafe(RetVal);
 
+      if (auto *ErrMsg = R.getOutOfBandError()) {
+        SDR(make_error<StringError>(ErrMsg, inconvertibleErrorCode()),
+            std::move(RetVal));
+        return;
+      }
+
       SPSInputBuffer IB(R.data(), R.size());
       if (auto Err = detail::ResultDeserializer<SPSRetTagT, RetT>::deserialize(
               RetVal, R.data(), R.size()))

diff  --git a/llvm/unittests/ExecutionEngine/Orc/WrapperFunctionUtilsTest.cpp b/llvm/unittests/ExecutionEngine/Orc/WrapperFunctionUtilsTest.cpp
index d672fcf11848f..b94c123ae22b3 100644
--- a/llvm/unittests/ExecutionEngine/Orc/WrapperFunctionUtilsTest.cpp
+++ b/llvm/unittests/ExecutionEngine/Orc/WrapperFunctionUtilsTest.cpp
@@ -8,6 +8,7 @@
 
 #include "llvm/ExecutionEngine/Orc/Shared/WrapperFunctionUtils.h"
 #include "llvm/ADT/FunctionExtras.h"
+#include "llvm/Testing/Support/Error.h"
 #include "gtest/gtest.h"
 
 #include <future>
@@ -142,3 +143,19 @@ TEST(WrapperFunctionUtilsTest, WrapperFunctionCallAndHandleAsyncRet) {
       addAsyncWrapper, Result, 1, 2));
   EXPECT_EQ(Result, (int32_t)3);
 }
+
+static WrapperFunctionResult failingWrapper(const char *ArgData,
+                                            size_t ArgSize) {
+  return WrapperFunctionResult::createOutOfBandError("failed");
+}
+
+void asyncFailingWrapperCaller(unique_function<void(WrapperFunctionResult)> F,
+                               const char *ArgData, size_t ArgSize) {
+  F(failingWrapper(ArgData, ArgSize));
+}
+
+TEST(WrapperFunctionUtilsTest, WrapperFunctionCallFailingAsync) {
+  WrapperFunction<void()>::callAsync(asyncFailingWrapperCaller, [](Error Err) {
+    EXPECT_THAT_ERROR(std::move(Err), Failed());
+  });
+}


        


More information about the llvm-commits mailing list