Skip to content

Commit 1c53cad

Browse files
committed
[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
1 parent 35b0b1a commit 1c53cad

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

compiler-rt/lib/orc/c_api.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ static inline __orc_rt_CWrapperFunctionResult
9595
__orc_rt_CWrapperFunctionResultAllocate(size_t Size) {
9696
__orc_rt_CWrapperFunctionResult R;
9797
R.Size = Size;
98+
// If Size is 0 ValuePtr must be 0 or it is considered an out-of-band error.
99+
R.Data.ValuePtr = 0;
98100
if (Size > sizeof(R.Data.Value))
99101
R.Data.ValuePtr = (char *)malloc(Size);
100102
return R;

compiler-rt/lib/orc/unittests/c_api_test.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ TEST(CAPITest, CWrapperFunctionResultInit) {
3030
TEST(CAPITest, CWrapperFunctionResultAllocSmall) {
3131
constexpr size_t SmallAllocSize = sizeof(const char *);
3232

33-
__orc_rt_CWrapperFunctionResult R;
34-
char *DataPtr = __orc_rt_CWrapperFunctionResultAllocate(&R, SmallAllocSize);
33+
auto R = __orc_rt_CWrapperFunctionResultAllocate(SmallAllocSize);
34+
char *DataPtr = __orc_rt_CWrapperFunctionResultData(&R);
3535

3636
for (size_t I = 0; I != SmallAllocSize; ++I)
3737
DataPtr[I] = 0x55 + I;
@@ -60,8 +60,8 @@ TEST(CAPITest, CWrapperFunctionResultAllocSmall) {
6060
TEST(CAPITest, CWrapperFunctionResultAllocLarge) {
6161
constexpr size_t LargeAllocSize = sizeof(const char *) + 1;
6262

63-
__orc_rt_CWrapperFunctionResult R;
64-
char *DataPtr = __orc_rt_CWrapperFunctionResultAllocate(&R, LargeAllocSize);
63+
auto R = __orc_rt_CWrapperFunctionResultAllocate(LargeAllocSize);
64+
char *DataPtr = __orc_rt_CWrapperFunctionResultData(&R);
6565

6666
for (size_t I = 0; I != LargeAllocSize; ++I)
6767
DataPtr[I] = 0x55 + I;

0 commit comments

Comments
 (0)