llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

Length parameters for the C API should be 'size_t', not 'unsigned'.

Open llvmbot opened this issue 15 years ago • 1 comments

Bugzilla Link 9242
Resolution WONTFIX
Resolved on May 01, 2020 22:10
Version 2.8
OS All
Reporter LLVM Bugzilla Contributor
CC @ekatz

Extended Description

A lot of the C wrapper functions take a pointer and a length when expecting a list of things. For instance, the signature of LLVMBuildCall:

... LLVMBuildCall(..., LLVMValueRef* Args, unsigned NumArgs,...)

Usually, unsigned i declares i as 32 bit unsigned integer. On 32 bit architectures, this can adequately index a pointer and all is well. On 64 bit architectures, however, a 64 bit unsigned integer is required to do this. The size_t type (in cstdint) does this job. In the above example, NumArgs should be declared as size_t NumArgs.

Incidentally, this bugs me as I'm using the C API from D. D arrays have a pointer and a length -- the length is declared as size_t. when using the above, I can create a D array of LLVMValueRefs and then pass it like

LLVMBuildCall(..., args.ptr, args.length,...)

Except if I'm building for 64 bit, I have to explicitly cast the length to uint to call LLVM.

llvmbot avatar Feb 18 '11 03:02 llvmbot

There is a patch I uploaded for review in https://reviews.llvm.org/D78746. But it will break the ABI, which complicates the solution too much for me (or seems to be anyone else right now) to pursue.

I am closing this bug as it is almost a decade old, and there seems to be no other interest in this change.

Feel free to reopen this issue, if the need rises.

ekatz avatar May 02 '20 05:05 ekatz