[compiler-rt] 68c1610 - [ORC-RT] Fix void function handling in the WrapperFunction utility.

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 14 22:52:50 PDT 2021


Author: Lang Hames
Date: 2021-06-15T15:49:40+10:00
New Revision: 68c161090ef6fe83218af6f627170ae56e5800b1

URL: https://github.com/llvm/llvm-project/commit/68c161090ef6fe83218af6f627170ae56e5800b1
DIFF: https://github.com/llvm/llvm-project/commit/68c161090ef6fe83218af6f627170ae56e5800b1.diff

LOG: [ORC-RT] Fix void function handling in the WrapperFunction utility.

Handlers returning void previously caused compile errors. Fix that by
substituting SPSEmpty placeholder values.

Added: 
    

Modified: 
    compiler-rt/lib/orc/unittests/wrapper_function_utils_test.cpp
    compiler-rt/lib/orc/wrapper_function_utils.h

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/orc/unittests/wrapper_function_utils_test.cpp b/compiler-rt/lib/orc/unittests/wrapper_function_utils_test.cpp
index 410f0aa90314f..12f4a93dceaaa 100644
--- a/compiler-rt/lib/orc/unittests/wrapper_function_utils_test.cpp
+++ b/compiler-rt/lib/orc/unittests/wrapper_function_utils_test.cpp
@@ -66,6 +66,13 @@ TEST(WrapperFunctionUtilsTest, WrapperFunctionResultFromOutOfBandError) {
   EXPECT_TRUE(strcmp(R.getOutOfBandError(), TestString) == 0);
 }
 
+static void voidNoop() {}
+
+static __orc_rt_CWrapperFunctionResult voidNoopWrapper(const char *ArgData,
+                                                       size_t ArgSize) {
+  return WrapperFunction<void()>::handle(ArgData, ArgSize, voidNoop).release();
+}
+
 static __orc_rt_CWrapperFunctionResult addWrapper(const char *ArgData,
                                                   size_t ArgSize) {
   return WrapperFunction<int32_t(int32_t, int32_t)>::handle(
@@ -86,7 +93,11 @@ __orc_rt_jit_dispatch(__orc_rt_Opaque *Ctx, const void *FnTag,
       ArgData, ArgSize);
 }
 
-TEST(WrapperFunctionUtilsTest, WrapperFunctionCallAndHandle) {
+TEST(WrapperFunctionUtilsTest, WrapperFunctionCallVoidNoopAndHandle) {
+  EXPECT_FALSE(!!WrapperFunction<void()>::call((void *)&voidNoopWrapper));
+}
+
+TEST(WrapperFunctionUtilsTest, WrapperFunctionCallAddWrapperAndHandle) {
   int32_t Result;
   EXPECT_FALSE(!!WrapperFunction<int32_t(int32_t, int32_t)>::call(
       (void *)&addWrapper, Result, 1, 2));

diff  --git a/compiler-rt/lib/orc/wrapper_function_utils.h b/compiler-rt/lib/orc/wrapper_function_utils.h
index 08f17abe794c8..cf027e7944b66 100644
--- a/compiler-rt/lib/orc/wrapper_function_utils.h
+++ b/compiler-rt/lib/orc/wrapper_function_utils.h
@@ -128,6 +128,25 @@ serializeViaSPSToWrapperFunctionResult(const ArgTs &...Args) {
   return Result;
 }
 
+template <typename RetT> class WrapperFunctionHandlerCaller {
+public:
+  template <typename HandlerT, typename ArgTupleT, std::size_t... I>
+  static decltype(auto) call(HandlerT &&H, ArgTupleT &Args,
+                             std::index_sequence<I...>) {
+    return std::forward<HandlerT>(H)(std::get<I>(Args)...);
+  }
+};
+
+template <> class WrapperFunctionHandlerCaller<void> {
+public:
+  template <typename HandlerT, typename ArgTupleT, std::size_t... I>
+  static SPSEmpty call(HandlerT &&H, ArgTupleT &Args,
+                       std::index_sequence<I...>) {
+    std::forward<HandlerT>(H)(std::get<I>(Args)...);
+    return SPSEmpty();
+  }
+};
+
 template <typename WrapperFunctionImplT,
           template <typename> class ResultSerializer, typename... SPSTagTs>
 class WrapperFunctionHandlerHelper
@@ -151,8 +170,11 @@ class WrapperFunctionHandlerHelper<RetT(ArgTs...), ResultSerializer,
       return WrapperFunctionResult::createOutOfBandError(
           "Could not deserialize arguments for wrapper function call");
 
-    if (auto Result = ResultSerializer<RetT>::serialize(
-            call(std::forward<HandlerT>(H), Args, ArgIndices{})))
+    auto HandlerResult = WrapperFunctionHandlerCaller<RetT>::call(
+        std::forward<HandlerT>(H), Args, ArgIndices{});
+
+    if (auto Result = ResultSerializer<decltype(HandlerResult)>::serialize(
+            std::move(HandlerResult)))
       return std::move(*Result);
     else
       return WrapperFunctionResult::createOutOfBandError(
@@ -167,11 +189,6 @@ class WrapperFunctionHandlerHelper<RetT(ArgTs...), ResultSerializer,
     return SPSArgList<SPSTagTs...>::deserialize(IB, std::get<I>(Args)...);
   }
 
-  template <typename HandlerT, std::size_t... I>
-  static decltype(auto) call(HandlerT &&H, ArgTuple &Args,
-                             std::index_sequence<I...>) {
-    return std::forward<HandlerT>(H)(std::get<I>(Args)...);
-  }
 };
 
 // Map function references to function types.


        


More information about the llvm-commits mailing list