Reputation: 3936
If you compile the following with "clang -S -emit-llvm struct.c"
struct _mystruct {
long long int a;
long long int b;
};
struct _mystruct foo(struct _mystruct s) {
s.a += 1;
return s;
}
int main(void) {
struct _mystruct s;
s.a = 8;
s.b = 9;
s = foo(s);
return s.a;
}
... you get (among other things):
define { i64, i64 } @foo(i64 %s.coerce0, i64 %s.coerce1) #0 {
Why does clang split the argument to foo in two? Is there any way I can prevent it from doing that? I want to be able to call it from other LLVM generated code that expects only one argument to foo.
Upvotes: 1
Views: 389
Reputation: 273844
Since LLVM has no way to represent it, Clang encodes the platform ABI this way. In this particular example, it's struct passing by-value which is extremely ABI specific. You will notice this if you provide different target triple to clang - you'll notice that the emitted code is different. I assume from the question this is run on a x64 machine where structs can be passed in registers.
Upvotes: 1