[LLVMdev] struct as a function argument

Zvonimir Rakamaric zrakamar at gmail.com
Sat Sep 29 13:00:57 PDT 2007


Hi everybody!

I recently started using llvm in a project on inferring additional
information about pointers based on their types, casts, etc. The
following simple example is giving me a headache :):

typedef struct {
  int a;
  short b, c;
  int d, e, f;
} foo;

void bar(foo f) {
  short s;
  s = f.b;
}

int main(void) {
  foo p;
  bar(p);
}

Because llvm doesn't allow structures and arrays to be passed as
arguments, the llvm intermediate format output for this C program
looks like this:
- the signature of function bar becomes void @bar(i64 %f.0.0, i64
%f.0.1, i32 %f.1)
- before the call to function bar, structure foo is casted to
structure { [2 x i64], i32 } and each element of that structure is
read into integer variables, which are then used as parameters for the
call
- in the beginning of function bar, the same process is repeated, just backwards

Is this the default llvm-gcc behaviour? Could it be changed somehow?
For instance, instead of casting a structure essentially to an array
of integers, one could maybe read the structure field by field, and
than pass those as arguments....

If the way llvm translates such function calls can't be changed, is
there any way to get the original function signature?

Thanks!

Cheers,
-- Zvonimir



More information about the llvm-dev mailing list