[LLVMdev] Mapping of class derivated and interfaces

Nicola Lugato nicola.lugato at gmail.com
Fri Aug 26 00:24:17 PDT 2005

> In any case when you
> want to obtain a base pointer to a "derived" object (where derivation
> is implemented as you showed - with nesting) it's simply a matter of
> using getelementptr to obtain a pointer to the nested base object and
> using that.

Umm ok, but i've the strange feeling that i'm missing something..
First a simple question: getelementptr with index 0 just give me the
same pointer, right?

Ok, if it's so the example you gave me worked becouse the first
element of "derived" is the "base" portion, thus having the same
pointer. But what if it was not the first? For example with multiple
derivation only one class can be in the first position:

%base1 = type { int }
%base2 = type { sbyte }
%derived = type { %base1, %base2, long }

void myProc(base2 obj)

Now if you use get elementptr to obtain "base2" member of "derived" to
pass it to myProc, then you're basically passing a different pointer,
breaking instance identity among other things:

public Derived global_var = new ....;

void myProc(base2 obj)
   boolean b = (global_var == obj);  // this would be false!

   Derived alias = (Derived) obj; // this would break too btw

So what am i missing ? maybe to deal with multiple ereditation one
need some more "manadgement" code ? and does the optimizer still "see"
all relations and code features?

Thank you!

More information about the llvm-dev mailing list