[compiler-rt] 0e43f3b - [ORC][ORC-RT] Make WrapperFunctionCall::Create support void functions.
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 18 18:02:32 PDT 2022
Author: Lang Hames
Date: 2022-09-18T17:53:45-07:00
New Revision: 0e43f3b04d527776458df7aa1d7ce1787ff0b32f
URL: https://github.com/llvm/llvm-project/commit/0e43f3b04d527776458df7aa1d7ce1787ff0b32f
DIFF: https://github.com/llvm/llvm-project/commit/0e43f3b04d527776458df7aa1d7ce1787ff0b32f.diff
LOG: [ORC][ORC-RT] Make WrapperFunctionCall::Create support void functions.
Serialized calls to void-wrapper-functions should have zero bytes of argument
data, but accessing ArgData[0] may (and will, in the case of SmallVector) fail
if the argument data buffer is empty.
This commit fixes the issue by adding a check for empty argument buffers.
Added:
Modified:
compiler-rt/lib/orc/tests/unit/wrapper_function_utils_test.cpp
compiler-rt/lib/orc/wrapper_function_utils.h
llvm/include/llvm/ExecutionEngine/Orc/Shared/WrapperFunctionUtils.h
llvm/unittests/ExecutionEngine/Orc/WrapperFunctionUtilsTest.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/orc/tests/unit/wrapper_function_utils_test.cpp b/compiler-rt/lib/orc/tests/unit/wrapper_function_utils_test.cpp
index 031238307b4f0..8d4b9b3cba2b7 100644
--- a/compiler-rt/lib/orc/tests/unit/wrapper_function_utils_test.cpp
+++ b/compiler-rt/lib/orc/tests/unit/wrapper_function_utils_test.cpp
@@ -66,6 +66,10 @@ TEST(WrapperFunctionUtilsTest, WrapperFunctionResultFromOutOfBandError) {
EXPECT_TRUE(strcmp(R.getOutOfBandError(), TestString) == 0);
}
+TEST(WrapperFunctionUtilsTest, WrapperFunctionCCallCreateEmpty) {
+ EXPECT_TRUE(!!WrapperFunctionCall::Create<SPSArgList<>>(ExecutorAddr()));
+}
+
static void voidNoop() {}
static __orc_rt_CWrapperFunctionResult voidNoopWrapper(const char *ArgData,
diff --git a/compiler-rt/lib/orc/wrapper_function_utils.h b/compiler-rt/lib/orc/wrapper_function_utils.h
index 17aa8bb671fd7..b48891b3b750f 100644
--- a/compiler-rt/lib/orc/wrapper_function_utils.h
+++ b/compiler-rt/lib/orc/wrapper_function_utils.h
@@ -408,7 +408,8 @@ class WrapperFunctionCall {
const ArgTs &...Args) {
ArgDataBufferType ArgData;
ArgData.resize(SPSSerializer::size(Args...));
- SPSOutputBuffer OB(&ArgData[0], ArgData.size());
+ SPSOutputBuffer OB(ArgData.empty() ? nullptr : ArgData.data(),
+ ArgData.size());
if (SPSSerializer::serialize(OB, Args...))
return WrapperFunctionCall(FnAddr, std::move(ArgData));
return make_error<StringError>("Cannot serialize arguments for "
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/Shared/WrapperFunctionUtils.h b/llvm/include/llvm/ExecutionEngine/Orc/Shared/WrapperFunctionUtils.h
index eb3fb084b28b6..bdb5ac143c34a 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/Shared/WrapperFunctionUtils.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/Shared/WrapperFunctionUtils.h
@@ -636,7 +636,8 @@ class WrapperFunctionCall {
const ArgTs &...Args) {
ArgDataBufferType ArgData;
ArgData.resize(SPSSerializer::size(Args...));
- SPSOutputBuffer OB(&ArgData[0], ArgData.size());
+ SPSOutputBuffer OB(ArgData.empty() ? nullptr : ArgData.data(),
+ ArgData.size());
if (SPSSerializer::serialize(OB, Args...))
return WrapperFunctionCall(FnAddr, std::move(ArgData));
return make_error<StringError>("Cannot serialize arguments for "
diff --git a/llvm/unittests/ExecutionEngine/Orc/WrapperFunctionUtilsTest.cpp b/llvm/unittests/ExecutionEngine/Orc/WrapperFunctionUtilsTest.cpp
index b94c123ae22b3..1ed690ae9b986 100644
--- a/llvm/unittests/ExecutionEngine/Orc/WrapperFunctionUtilsTest.cpp
+++ b/llvm/unittests/ExecutionEngine/Orc/WrapperFunctionUtilsTest.cpp
@@ -58,6 +58,11 @@ TEST(WrapperFunctionUtilsTest, WrapperFunctionResultFromOutOfBandError) {
EXPECT_TRUE(strcmp(R.getOutOfBandError(), TestString) == 0);
}
+TEST(WrapperFunctionUtilsTest, WrapperFunctionCCallCreateEmpty) {
+ EXPECT_THAT_EXPECTED(
+ WrapperFunctionCall::Create<SPSArgList<>>(ExecutorAddr()), Succeeded());
+}
+
static void voidNoop() {}
class AddClass {
More information about the llvm-commits
mailing list