[LLVMdev] assumptions about varargs ABI

Chris Lattner sabre at nondot.org
Thu Sep 13 15:36:36 PDT 2007

On Thu, 13 Sep 2007, Jay Foad wrote:
> Various parts of LLVM seem to assume that the ABI for a varargs
> function is compatible with the ABI for a non-varargs function, so

This is due to 'K&R' C function handling.  In K&R and ANSI C, you can do 
stuff like this:

void foo();

void bar() {
    foo(1, 2, 3);

void foo(int a, int b, int c) {}

and it needs to work.

> (I don't think C guarantees that this will work, at least not in the
> version of the C99 standard I checked.)
> I'm trying to target a (proprietary) ABI where the ABI is rather
> different for varargs and non-varargs functions.

I am pretty sure it is required to work, otherwise you can't call a 
function with no prototype.

> Would it be reasonable to do the same optimisation at a call? That is,
> given some code that calls a function declared with no prototype:
>    void f();
>    ...
>    f(42);
> to bitcast the callee into a function type based on what the actual
> arguments being passed in are, as if the source had been:
>  ((void (*)(int))&f)(42);

Yes, I believe that would be safe.



More information about the llvm-dev mailing list