question on the signature of malloc

Hi all,

consider the following function from Core.cpp in LLVM 9.0.0:

LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef B, LLVMTypeRef Ty,

const char *Name) {

Type* ITy = Type::getInt32Ty(unwrap(B)->GetInsertBlock()->getContext());

Constant* AllocSize = ConstantExpr::getSizeOf(unwrap(Ty));

AllocSize = ConstantExpr::getTruncOrBitCast(AllocSize, ITy);

Instruction* Malloc = CallInst::CreateMalloc(unwrap(B)->GetInsertBlock(),

ITy, unwrap(Ty), AllocSize,

nullptr, nullptr, “”);

return wrap(unwrap(B)->Insert(Malloc, Twine(Name)));

}

In this code I highlighted the line which I have question on. the signature of malloc is

void *malloc(size_t size);

is this suspiciously wrong that this builder assumes size_t is 32 bit int? will LLVM backend smart enough to link the right one, which in 64 bit system is 64 bit int?

It’s simply wrong.

On many 64-bit targets, it will appear to work anyway, depending on your luck, due to the way calling conventions works.

-Eli

Thank you for your confirmation Eli.