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. The assembler also rejects '{i32,i32}(i32)' with the error 'LLVM Functions cannot return aggregates'. 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'. Finally, I suggest defining these additional terms in the type-classification section: - value type - scalar type - aggregate type Best Regards, Jon
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
Hi,> 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.they must be first-class types or opaque types.> The assembler also rejects > '{i32,i32}(i32)' with the error 'LLVM Functions cannot return > aggregates'. 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 documentation is based on svn head, which is currently getting support for functions returning multiple values. This is done by having the function return a struct type (the struct type cannot contain other structs: first-class types only).> Finally, I suggest defining these additional terms in the > type-classification section: > - value type > - scalar type > - aggregate typeGood idea. Want to prepare a patch? Best wishes, Duncan.
Duncan Sands wrote: [snip]>> Finally, I suggest defining these additional terms in the >> type-classification section: >> - value type >> - scalar type >> - aggregate type > > Good idea. Want to prepare a patch?Sorry, I wasn't clear. What is a value type? A scalar type? An aggregate type? Best Regards, Jon
On Mar 30, 2008, at 3:09 PM, Duncan Sands wrote:>> The assembler also rejects >> '{i32,i32}(i32)' with the error 'LLVM Functions cannot return >> aggregates'. 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 documentation is based on svn head, which is currently getting > support for functions returning multiple values. This is done by > having the function return a struct type (the struct type cannot > contain other structs: first-class types only).Yup. I missed the beginning of this thread. Please file PR for the error 'LLVM Functions cannot return aggregates'. As Duncan says, we are working on this support in svn head. - Devang
Hi,> - value typethis seems to mean first-class or opaque. I think it would be best to change the assertion message to: Function arguments must be first-class types or opaque! This message is used in several places, so all should be changed.> - scalar typeI think this is the same as first-class.> - aggregate typeI think this is the same as a sized-type that is not first-class. Ciao, Duncan.