[compiler-rt] 1c53cad - [orc] Fix unit tests that use ORC C API

Ben Langmuir via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 24 14:20:01 PDT 2021


Author: Ben Langmuir
Date: 2021-08-24T14:19:46-07:00
New Revision: 1c53cadf08c07fb3fa70993c6210355c58c3b149

URL: https://github.com/llvm/llvm-project/commit/1c53cadf08c07fb3fa70993c6210355c58c3b149
DIFF: https://github.com/llvm/llvm-project/commit/1c53cadf08c07fb3fa70993c6210355c58c3b149.diff

LOG: [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

Added: 
    

Modified: 
    compiler-rt/lib/orc/c_api.h
    compiler-rt/lib/orc/unittests/c_api_test.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/orc/c_api.h b/compiler-rt/lib/orc/c_api.h
index 18eb96d80b37d..47f46b891d966 100644
--- a/compiler-rt/lib/orc/c_api.h
+++ b/compiler-rt/lib/orc/c_api.h
@@ -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;

diff  --git a/compiler-rt/lib/orc/unittests/c_api_test.cpp b/compiler-rt/lib/orc/unittests/c_api_test.cpp
index 4583feb98a136..a14ea18a78dce 100644
--- 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, 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;


        


More information about the llvm-commits mailing list