[cfe-dev] ABI-specific or shared this/ret adjustment types?

Timur Iskhodzhanov timurrrr at google.com
Thu Nov 7 05:26:13 PST 2013


Hi John,

We've recently added support for this/ret adjusting thunks when using
-cxx-abi microsoft.

As the exact procedures of this/ret adjustments are different in
different ABIs, we need to store different sets of values too.
The organization of CGVTables and VTableContextBase didn't allow for a
simple way to get around this though.
We ended up using unions of structs, see
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/ABI.h?r1=159616&r2=194132&diff_format=h

If you don't think this is the right thing to do, I'm willing to
refactor it better.

Some considerations below:
1) I'd argue the Thunk parts of ABI.h should be moved from Basic to
AST. They are only used in AST+CodeGen anyways.
WDYT about moving them to lib/AST/VTableBuilder.h ?

2) CGVTables.cpp does the hard work of defining GVs and Functions well
and I don't see any reason to separate the handling of thunks in
CGVTables.cpp into ABI-specific parts. It also passes the this/ret
around to the virtual CGCXXABI::perform{This,Ret}Adjustment() methods
by reference.

3) CGVTables get the thunks from VTableContextBase::getThunkInfo(GD)
as a vector of ThunkInfo's.
Ditto VTableLayout provides a pair of iterators to
pair<uint64_t,ThunkInfo> via vtable_thunk_{begin,end}().
This doesn't work well if I want to have a class hierarchy like
ThunkInfoBase, ItaniumThunkInfo, etc.

One option is to use provide const pointers to ThunkInfo instead, but
that implies some extra work to do the memory management.
Probably we can store ABI-specific ThunkInfo's in an internal vector?
We don't add new thunks to the vector after it's built...

Another option is to change the interface to "getThunkInfo(GD, idx)"
returning a const reference (const pointer?) to ThunkInfoBase and add
a "getNumThunks(GD)" method, ditto for VTableLayout.

What do you think?

--
Thanks,
Timur



More information about the cfe-dev mailing list