[LLVMdev] C struct as function argument

Anton Korobeynikov anton at korobeynikov.info
Mon Jun 20 12:39:17 PDT 2011


Hello Michael,

> The module dump suggests everything is right, i can see in the function call the struct with the values 10 and 25, but the function is only received the 10 for the x field, nothing for the y field.  Am I missing something?
You're missing the Platform ABI. I assume you're on x86-64, then your
struct (according to the ABI) should be passed in a single 64 bit
register as a whole. However you're passing {10, 25} as two separate
32-bit values. Given that 32-bit operations do implicit zero extension
it's clear why you have 0 as the second value.

To be precise: the C code expects to receive 25 in the top 32 bits of
the first argument register, but you're passing the value in the low
32 bits of the second argument register.

-- 
With best regards, Anton Korobeynikov
Faculty of Mathematics and Mechanics, Saint Petersburg State University




More information about the llvm-dev mailing list