mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-18 12:46:51 +00:00
[orc] Fix unit tests that use ORC C API
* c_api_tests was failing to build after the API change to __orc_rt_CWrapperFunctionResultAllocate * wrapper_function_utils_test was causing an assertion failure, because it was creating a result for `void(void)` with Size = 0, but seeing an uninitialized pointer, which it considered to be an out-of-bound error. I noticed locally that making modifications to c_api.h is not causing these unit tests to be rebuilt, which may be how the bug slipped in in the first place. Differential Revision: https://reviews.llvm.org/D108649
This commit is contained in:
parent
35b0b1a64a
commit
1c53cadf08
@ -95,6 +95,8 @@ static inline __orc_rt_CWrapperFunctionResult
|
||||
__orc_rt_CWrapperFunctionResultAllocate(size_t Size) {
|
||||
__orc_rt_CWrapperFunctionResult R;
|
||||
R.Size = Size;
|
||||
// If Size is 0 ValuePtr must be 0 or it is considered an out-of-band error.
|
||||
R.Data.ValuePtr = 0;
|
||||
if (Size > sizeof(R.Data.Value))
|
||||
R.Data.ValuePtr = (char *)malloc(Size);
|
||||
return R;
|
||||
|
@ -30,8 +30,8 @@ TEST(CAPITest, CWrapperFunctionResultInit) {
|
||||
TEST(CAPITest, CWrapperFunctionResultAllocSmall) {
|
||||
constexpr size_t SmallAllocSize = sizeof(const char *);
|
||||
|
||||
__orc_rt_CWrapperFunctionResult R;
|
||||
char *DataPtr = __orc_rt_CWrapperFunctionResultAllocate(&R, SmallAllocSize);
|
||||
auto R = __orc_rt_CWrapperFunctionResultAllocate(SmallAllocSize);
|
||||
char *DataPtr = __orc_rt_CWrapperFunctionResultData(&R);
|
||||
|
||||
for (size_t I = 0; I != SmallAllocSize; ++I)
|
||||
DataPtr[I] = 0x55 + I;
|
||||
@ -60,8 +60,8 @@ TEST(CAPITest, CWrapperFunctionResultAllocSmall) {
|
||||
TEST(CAPITest, CWrapperFunctionResultAllocLarge) {
|
||||
constexpr size_t LargeAllocSize = sizeof(const char *) + 1;
|
||||
|
||||
__orc_rt_CWrapperFunctionResult R;
|
||||
char *DataPtr = __orc_rt_CWrapperFunctionResultAllocate(&R, LargeAllocSize);
|
||||
auto R = __orc_rt_CWrapperFunctionResultAllocate(LargeAllocSize);
|
||||
char *DataPtr = __orc_rt_CWrapperFunctionResultData(&R);
|
||||
|
||||
for (size_t I = 0; I != LargeAllocSize; ++I)
|
||||
DataPtr[I] = 0x55 + I;
|
||||
|
Loading…
x
Reference in New Issue
Block a user