[cfe-dev] AST's VTableContext object and the Microsoft C++ ABI

John McCall rjmccall at apple.com
Sat Jun 23 12:04:16 PDT 2012


On Jun 17, 2012, at 2:08 PM, Charles Davis wrote:
> I'm working on improving support for v-tables under the Microsoft C++ ABI, and while poking around in IRGen, I discovered the VTableContext class that lives in the AST library.
> 
> This class is responsible for generally laying out the (single, unless the class needs a construction v-table) v-table for each class that needs one. It is very specific to the Itanium ABI concept of a virtual table, which means it can't be used as-is for the Microsoft ABI. Trouble is, it's used by various pieces of IRGen--which is how I discovered it.
> 
> So, I'm asking for your advice. What should I do about this?
> 
> - Should I make certain methods of VTableContext virtual, and override them for the Microsoft ABI?
> - Should I hide this class behind the CXXABI objects? If I go this route, I'll have to indirect the pieces of IRGen currently using this object through the CGCXXABI object.

This is right way to go.  Having a single implementation with some special cases works for class layout because the *questions* that we want to ask of a class layout remain largely the same across ABIs:  for example, "what is the offset of this field?" or "what is the offset of this base class object?" or "what is the size of this type, laid out as a complete object?"  That's just not true of v-tables, due mostly to the distinction between vf-tables and vb-tables, but also because entire significant concepts (e.g., a VTT or a construction vtable) are inapplicable.  So it makes sense that generic IR generation should defer these things to the ABI object, which knows the right questions to ask.

John.



More information about the cfe-dev mailing list