[LLVMdev] Calling C-language variadic functions

Gregory Junker gjunker at dayark.com
Tue May 8 22:56:57 PDT 2012


On 5/8/2012 7:52 PM, =?utf-8?Q?=C3=93scar_Fuentes?= wrote:
> Gregory Junker<gjunker at dayark.com>  writes:
>
>> Such as printf, etc., from IR created using the API (IRBuilder).
>>
>> Google hasn't provided much help, and I can't find anything relevant in
>> the docs (the docs talk about how to do varargs in LLVM ASM, but not how
>> to call an external vararg function that exists in a library that gets
>> linked to the LLVM module).
>>
>> Is there something special I need to do?
>
> Declare the function with the right type:
>
> FunctionType* FuncTy_7 = FunctionType::get(
>    /*Result=*/IntegerType::get(mod->getContext(), 32),
>    /*Params=*/FuncTy_7_args,
>    /*isVarArg=*/true);

Ah this must be the primary issue -- will give that a shot, thanks!

>
> I guess that you are not using `verifyModule' before generating the
> native code, because the sort of declaration/call mismatch you are
> experiencing is detected there. Or you are calling the external vaarg
> function with the same number of parameters listed on the faulty
> declaration, in which case `verifyModule' has no reason for complaning.

I am not, but I will start doing so.

Greg



More information about the llvm-dev mailing list