[compiler-rt] 2f53fcc - Fix compilation errors in C API when using C compiler

Ben Langmuir via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 24 10:13:30 PDT 2021


Author: Ben Langmuir
Date: 2021-08-24T10:12:32-07:00
New Revision: 2f53fcc831e2f5ceee0d42c41766d9231049e46b

URL: https://github.com/llvm/llvm-project/commit/2f53fcc831e2f5ceee0d42c41766d9231049e46b
DIFF: https://github.com/llvm/llvm-project/commit/2f53fcc831e2f5ceee0d42c41766d9231049e46b.diff

LOG: Fix compilation errors in C API when using C compiler

* Cannot use sizeof() on another union member
* nullptr vs NULL
* () vs (void)

Incidentally, fix an incorrect comment about memory ownership on the
argument to __orc_rt_CreateCWrapperFunctionResultFromOutOfBandError,
which is copied, not moved.

Added: 
    

Modified: 
    compiler-rt/lib/orc/c_api.h
    llvm/include/llvm-c/Transforms/PassBuilder.h

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/orc/c_api.h b/compiler-rt/lib/orc/c_api.h
index a3f3acb388779..18eb96d80b37d 100644
--- a/compiler-rt/lib/orc/c_api.h
+++ b/compiler-rt/lib/orc/c_api.h
@@ -50,7 +50,7 @@ ORC_RT_C_EXTERN_C_BEGIN
 
 typedef union {
   char *ValuePtr;
-  char Value[sizeof(ValuePtr)];
+  char Value[sizeof(char *)];
 } __orc_rt_CWrapperFunctionResultDataUnion;
 
 /**
@@ -133,8 +133,8 @@ __orc_rt_CreateCWrapperFunctionResultFromString(const char *Source) {
  * Create an __orc_rt_CWrapperFunctionResult representing an out-of-band
  * error.
  *
- * This function takes ownership of the string argument which must have been
- * allocated with malloc.
+ * This function copies the input string. The client is responsible for freeing
+ * the ErrMsg arg.
  */
 static inline __orc_rt_CWrapperFunctionResult
 __orc_rt_CreateCWrapperFunctionResultFromOutOfBandError(const char *ErrMsg) {
@@ -163,7 +163,7 @@ __orc_rt_DisposeCWrapperFunctionResult(__orc_rt_CWrapperFunctionResult *R) {
  */
 static inline char *
 __orc_rt_CWrapperFunctionResultData(__orc_rt_CWrapperFunctionResult *R) {
-  assert((R->Size != 0 || R->Data.ValuePtr == nullptr) &&
+  assert((R->Size != 0 || R->Data.ValuePtr == NULL) &&
          "Cannot get data for out-of-band error value");
   return R->Size > sizeof(R->Data.Value) ? R->Data.ValuePtr : R->Data.Value;
 }
@@ -175,7 +175,7 @@ __orc_rt_CWrapperFunctionResultData(__orc_rt_CWrapperFunctionResult *R) {
  */
 static inline size_t
 __orc_rt_CWrapperFunctionResultSize(const __orc_rt_CWrapperFunctionResult *R) {
-  assert((R->Size != 0 || R->Data.ValuePtr == nullptr) &&
+  assert((R->Size != 0 || R->Data.ValuePtr == NULL) &&
          "Cannot get size for out-of-band error value");
   return R->Size;
 }

diff  --git a/llvm/include/llvm-c/Transforms/PassBuilder.h b/llvm/include/llvm-c/Transforms/PassBuilder.h
index 5635f10d68770..0de9be610bbee 100644
--- a/llvm/include/llvm-c/Transforms/PassBuilder.h
+++ b/llvm/include/llvm-c/Transforms/PassBuilder.h
@@ -50,7 +50,7 @@ LLVMErrorRef LLVMRunPasses(LLVMModuleRef M, const char *Passes,
  * responsible for it. The client should call LLVMDisposePassBuilderOptions
  * to free the pass builder options.
  */
-LLVMPassBuilderOptionsRef LLVMCreatePassBuilderOptions();
+LLVMPassBuilderOptionsRef LLVMCreatePassBuilderOptions(void);
 
 /**
  * Toggle adding the VerifierPass for the PassBuilder, ensuring all functions


        


More information about the llvm-commits mailing list