diff --git a/compiler-rt/lib/orc/c_api.h b/compiler-rt/lib/orc/c_api.h --- a/compiler-rt/lib/orc/c_api.h +++ b/compiler-rt/lib/orc/c_api.h @@ -95,6 +95,8 @@ __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; diff --git a/compiler-rt/lib/orc/unittests/c_api_test.cpp b/compiler-rt/lib/orc/unittests/c_api_test.cpp --- a/compiler-rt/lib/orc/unittests/c_api_test.cpp +++ b/compiler-rt/lib/orc/unittests/c_api_test.cpp @@ -30,8 +30,8 @@ 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, 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;