[LLVMdev] Problem returning aggregate struct (complex number) by value

Eli Friedman eli.friedman at gmail.com
Fri Apr 2 16:56:50 PDT 2010


On Fri, Apr 2, 2010 at 1:12 PM, Andrew Friedley <afriedle at indiana.edu> wrote:
> Duncan Sands wrote:
>> Hi Andrew,
>>
>>> %0 = type { float, float }
>>>
>>> define %0 @test600() {
>>> entry:
>>>     ret %0 { float 4.200000e+01, float 3.500000e+01 }
>>> }
>>>
>>>
>>> Running that through llc, the x86-64 assembly looks like this (abbreviated):
>>
>> unfortunately the x86-64 ABI says that complex numbers are *not* passed the
>> same as a struct containing two floats.  Your LLVM IR is not ABI conformant
>> and thus will not interact properly with ABI conformant code, like that produced
>> by llvm-gcc.
>
> Thanks for the response.  I'm aware of that, but dont think I quite
> understand why that affects me here -- I'm using structs in all cases
> (although as an abstraction for a complex number), not actual C99
> complex.  Does LLVM just assume that I really mean C99 complex when I'm
> working with a struct of two floats?
>
> Even so this doesn't answer my question, of what can I do to make this
> work? :)

The correct solution in this specific case is to have your function
return "double".  The general solution is to see what llvm-gcc or
clang outputs for a particular C function.

-Eli




More information about the llvm-dev mailing list