[cfe-dev] Adding support for multiple non-virtual inheritance for -cxx-abi microsoft

Timur Iskhodzhanov timurrrr at google.com
Mon Apr 8 09:29:10 PDT 2013


Hi John,

I wanted to work on the multiple non-virtual inheritance support for
the Microsoft ABI.
I already have a local patch that generates code that works, but I
think it requires quite some polishing.

There are a few general questions I'd like to ask first as the Clang
architecture assumes some high-level things that are not true in the
Microsoft ABI.

Let's assume we have
struct A { virtual void a(); }
struct B { virtual void b(); }
struct C : A, B { virtual void b(); }

In Itanium ABI, C::b takes C* as an implicit "this" parameter;
in order to work with B* pointers, there is an adjusting thunk in the
C's vtable slot for "b".

In Microsoft ABI, C::b takes B* as an implicit "this" parameter.
No thunks are needed for vtable generation.
I've only observed thunks when I took a member pointer for a class
with multiple inheritance, but it was not specific to any particular
method.

So here are the questions:

Q1) Passing this to overriden methods
I assume the type of C::b should be "void <...>(%struct.B* %this)" -
does this look reasonable?
Can you suggest how to change the CodeGen to handle this appropriately?
Do you know a non-painful way to do that?
I think I'll need to:
a) adjust CodeGenTypes::arrangeCXXMethodType
  ... and now it needs not only the RD and FTP, but MD also.
  Instead of "argTypes.push_back(GetThisType(Context, RD));"
  I'll probably need to ask CGCXXABI on the this type?
  Is there an easy way to tell the most base class which declared a
given virtual method?

b) adjust all the places where the method may be called.
btw, is there an easy way to know the base class offset in a given
class in the CGCall ?
Or do I need to move some code from VTableBuilder for that?

Q2) thunks
As thunks are not needed for vtable generation, I don't think we need
to emit them when there are no virtual bases.
I'm not sure how to handle this in VTableBuilder as there are quite a
few places where this can be possible.
One option is to short-circuit the method iteration in
VTableBuilder::ComputeThisAdjustments if there are no virtual bases,
the other is to change the ComputeThisAdjustment method to work as if
the adjustment was not needed.

Q3) vtable layout
In Itanium ABI, there's one vtable for each class.
The non-virtual bases get address points somewhere in the middle of this vtable.

In Microsoft ABI, each base gets its own vtable, e.g. for the class C we'll have
"C vtable for the A part" and "C vtable for the B part".

We do the same in Clang, but that'd require some API changes to
VTableBuilder - i.e. you'll need to know a pair of classes to generate
a vtable, not just one.
We can go our own Itanium-like way and emit one vtable with address
points and still make this ABI-compatible (this is how my local patch
works) but I have a bad feeling that this may fail to work when we
start supporting virtual inheritance.

Do you have any thoughts or suggestions on this?

--
Thanks!
Timur



More information about the cfe-dev mailing list