Thunks for MS ABI.

Hi all.

While I implementing vf-tables for MS ABI I met a problem.
In MS ABI vf-table defines by pair of CXXRecordDecl, for example

class first{
public:
   virtual void asdf() {}
};
class second : public virtual first {
public :
   int q;
     virtual void asdf() { q = 90; }
};
class third : public virtual second {
public:
   virtual void ff(){}
};

Class third has 2 vf-tables

class third size(24):

Hi all.

While I implementing vf-tables for MS ABI I met a problem.
In MS ABI vf-table defines by pair of CXXRecordDecl, for example

class first{
public:
virtual void asdf() {}
};
class second : public virtual first {
public :
int q;
virtual void asdf() { q = 90; }
};
class third : public virtual second {
public:
virtual void ff(){}
};

A quick explanation of how thunks work in the Itanium ABI:

Given the following:
struct first {
  virtual void asdf() = 0;
};
struct second : public virtual first {
public :
  int q;
  virtual void asdf();
};
void second::asdf() { q = 90; }

For this code, clang generates exactly one thunk: the one that lets a
call which is syntactically a call to first::asdf to forward to
second::asdf. No other thunk is necessary: any call which dynamically
resolves to second::asdf is either calling second::asdf or
first::asdf. Unless some other class defines an asdf method, clang
will never generate any other thunks for asdf, no matter what the
inheritance structure looks like.

If I want emit thunk , then I need to know record class(third) and base
class(first).
But getThunkInfo function has one parameter CXXMethodDecl and getParent
function returns first class.
How can I get third class record declaration?

For thunks like those in the Itanium ABI, the question you're asking
makes no sense: "third" is irrelevant to thunk emission. For a given
CXXMethodDecl, the set of necessary thunks is fixed; there is
precisely one thunk for "second::asdf" no matter how any other class
inheriting from "second" is defined.

If MS ABI thunks do actually require generating thunks upon the
definition of "third", you're going to have to essentially start from
scratch; the existing thunk code can only handle Itanium-style thunks.

-Eli

Thank you for your clarification.

  1. VTableContext stores all thunk information for each method if it`s need.
  2. So if method have 20 thunks(for example), getThunkInfo will return vector with 20 elements. And EmitThunks will emit all of them.
    Am I right?
  • Dmitry.

Yes, exactly.

-Eli