[LLVMdev] Function Parameter Requirements?

Óscar Fuentes ofv at wanadoo.es
Sun Mar 30 14:25:30 PDT 2008


Jon Sargeant <delta17 at cox.net> writes:

> I'm trying to find the requirements for function parameters in the 
> documentation.  The assembler rejects 'i32({i32,i32})' with the error 
> 'Function arguments must be value types!' so I'm guessing that each 
> parameter type must be a first-class type.

Right. You must pass either {i32,i32}* (a pointer to the structure) or
{i64} (a first-class value that contains your structure). This depends
on the calling convention and platform you are working on.

> The assembler also rejects 
> '{i32,i32}(i32)' with the error 'LLVM Functions cannot return 
> aggregates'.

This is a similar case. Your function's signaure should be:

void ({i32,i32}* sret, {i32})

(you pass an address for putting there the structure)

or

i64 ({i32})

(you use a i64 for packing the structure).

Again, this depends on your platform and calling convention. If you are
working with C++, the existence of copiers or destructors for the struct
may affect how you pass it.

A good idea is to check wath llvm-gcc does, compilent C code that is
equivalent to your case and reading the generated LLVM assembly
code. (Use -emit-llvm switch on llvm-gcc and then use the llvm-dis
tool). Another useful tool is llvm2cpp.

> This error seems to contradict the documentation which 
> states 'The return type of a function type is a scalar type or a void 
> type or a struct type'.

The docs are right, but perhaps not clear enough for a LLVM novice: the
attribute `sret' on the first argument of a function indicates that that
argument is in fact the "return type" of the function.

[snip]

-- 
Oscar




More information about the llvm-dev mailing list