[llvm-dev] Malloc signature errors

zealain via llvm-dev llvm-dev at lists.llvm.org
Fri Jun 18 03:36:07 PDT 2021


I have tried adding attributes like noalias as well, but that didn't help
either.

Generated by clang (works): %2 = call noalias i8* @malloc(i64 4096) #2
Generated by my pass (fails): i8*  %malloccall = call noalias i8*
@malloc(i64 4096)

I had a look at CallInstr::CreateMalloc as well and found out that it uses
module->getOrInsertFunction(), which seems a bit odd to me. I have then
also tried to get a pointer to the malloc function itself with
module->getFunction() and it turns out it couldn't find it. So that would
raise two additional questions:

1. Why does CallInstr::CreateMalloc define a new malloc function which
seems to be broken if it can't find the real one?
2. Why does it not find the malloc function in the first place if clang can
find it?

Regards,
Z

On Thu, Jun 17, 2021 at 7:49 PM David Blaikie <dblaikie at gmail.com> wrote:

> Might be missing the noalias attribute on the result?
>
> On Thu, Jun 17, 2021 at 10:46 AM zealain via llvm-dev <
> llvm-dev at lists.llvm.org> wrote:
>
>> Hello
>>
>> I am trying to insert malloc calls in my function pass, yet it keeps
>> complaining about the parameter type:
>>
>> Call parameter type does not match function signature!
>> i64 4096
>>  i8*  %malloccall = tail call i8* @malloc(i64 4096)
>>
>> Comparing this to a call generated by simply having a malloc in the C
>> code, I cannot spot significant differences. The following (generated by
>> clang) works just fine:
>>
>> %2 = call noalias i8* @malloc(i64 4096) #2
>>
>> Why does one work but the other doesn't? Below is the code I use to
>> generate the instruction:
>>
>> Type *int8Type = Type::getInt8Ty(this->currentFunction->getContext());
>> Type *int64Type = Type::getInt64Ty(this->currentFunction->getContext());
>>
>> auto allocSize = ConstantInt::get(int64Type, 4096);
>>
>> Instruction* mallocInstr =
>> CallInst::CreateMalloc(this->currentFunction->getEntryBlock().getFirstNonPHI(),
>>
>> int8Type->getPointerTo(), int8Type, allocSize,
>>                                                   nullptr, nullptr, "");
>>
>> I tried changing up the types already but didn't find a combination that
>> works yet. Any hints would be appreciated.
>>
>> Regards,
>> Z
>> _______________________________________________
>> LLVM Developers mailing list
>> llvm-dev at lists.llvm.org
>> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20210618/895116b8/attachment.html>


More information about the llvm-dev mailing list