[PATCH] D107995: Fix compilation errors in C API when using C compiler
Ben Langmuir via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 12 14:00:50 PDT 2021
benlangmuir created this revision.
benlangmuir added a reviewer: lhames.
Herald added a reviewer: deadalnix.
benlangmuir requested review of this revision.
Herald added projects: Sanitizers, LLVM.
Herald added subscribers: llvm-commits, Sanitizers.
Fix compilation errors when including C headers in C language mode instead of C++.
- 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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D107995
Files:
compiler-rt/lib/orc/c_api.h
llvm/include/llvm-c/Transforms/PassBuilder.h
Index: llvm/include/llvm-c/Transforms/PassBuilder.h
===================================================================
--- llvm/include/llvm-c/Transforms/PassBuilder.h
+++ llvm/include/llvm-c/Transforms/PassBuilder.h
@@ -50,7 +50,7 @@
* 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
Index: compiler-rt/lib/orc/c_api.h
===================================================================
--- compiler-rt/lib/orc/c_api.h
+++ compiler-rt/lib/orc/c_api.h
@@ -50,7 +50,7 @@
typedef union {
char *ValuePtr;
- char Value[sizeof(ValuePtr)];
+ char Value[sizeof(char *)];
} __orc_rt_CWrapperFunctionResultDataUnion;
/**
@@ -135,8 +135,8 @@
* 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) {
@@ -165,7 +165,7 @@
*/
static inline const char *
__orc_rt_CWrapperFunctionResultData(const __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;
}
@@ -177,7 +177,7 @@
*/
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;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107995.366096.patch
Type: text/x-patch
Size: 2060 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210812/d50e3cff/attachment.bin>
More information about the llvm-commits
mailing list