This is an archive of the discontinued LLVM Phabricator instance.

[ms-cxxabi] Fix the base/complete dtor logic.
Needs ReviewPublic

Authored by pcc on May 19 2013, 3:26 PM.
This revision needs review, but there are no reviewers specified.

Details

Reviewers
None
Summary

Previously it was thought that the Microsoft ABI used '?1' for
complete dtors. In fact, '?1' is for base dtors, and '?_D' is for
complete dtors. (Some confusion arose from documentation referring
to complete dtors as 'vbase dtors'.) The dtor forms other than the
base dtor are emitted by a TU when required by that TU, even when
the body is not present.

Also, fix the implicit parameter belonging to deleting destructors.
That parameter is an integer, not a boolean.

Diff Detail

Event Timeline

rnk added inline comments.May 20 2013, 5:53 AM
test/CodeGenCXX/microsoft-abi-structors.cpp
238

So, in the MS ABI, key methods basically don't exist, right? All class data is all comdat, all the time, and only emitted if it's used in the TU. At least that's what I see so far.

pcc added inline comments.May 20 2013, 7:17 AM
test/CodeGenCXX/microsoft-abi-structors.cpp
238

That's also my understanding.

Previously it was thought that the Microsoft ABI used '?1' for
complete dtors. In fact, '?1' is for base dtors, and '?_D' is for
complete dtors. (Some confusion arose from documentation referring
to complete dtors as 'vbase dtors'.)

Well if you look at the debug information CL generates for this code:

struct A { virtual ~A(); };
struct B : virtual A { virtual ~B(); };

you'll notice that ??1B@@UAE@XZ is B::~B
and ??_DB@@QAEXXZ is B::'vbase destructor'.

Yes, one needs to use a ?_D in order to destroy an object of a class with virtual bases - so "vbase dtor" means "the one that destroys the virtual bases as its last action" and yes it's similar to Itanium's complete destructors in this sense.

However, destroying an object of a class without virtual bases in Microsoft ABI doesn't need to use a ?_D destructor and it uses a ?1 dtor [and this saves us some size on each object file],
in contrast with the Itanium ABI which always uses complete dtors to destroy objects, but optimizes the object file sizes by using dtor type aliases.

Do you agree with this data points and reasoning?

I'd still prefer that we use ?1.

Can you for example let the CGCXXABI tell you which CXXDtorType to use to destroy an object of a given type?
Or at least add a few FIXME that this in fact should be ?1 but works for us as long as we define extra auxillary dtors.

lib/AST/MicrosoftMangle.cpp
509

Please add a test that checks mangling of a static in a destructor of a class with virtual bases

lib/CodeGen/CGCXX.cpp
244

This comment is no longer true?

You should also describe how Base/Complete/Deleting dtors work as a comment somewhere in MicrosoftCXXABI
or generalize the comments at the CXXDtorType definition
(e.g. Base = dtor to destroy this as a base or as a complete object if there are no virtual bases, etc)

test/CodeGenCXX/microsoft-abi-structors.cpp
55

I think these should be checked by an extra FileChecker invocation to be 100% they are not emitted in this TU.

247

how about
"of the auxillary dtor types, despite the base destructor is not being defined in this TU."

250

In fact, defining a vbase destructor is not required in this TU if we get back to using ?1 dtors for classes without virtual bases.

which always uses complete dtors to destroy objects

Correction: I've accidentally ignored the existence of deleting/virtual destructors while writing this, but it doesn't change the remaining logic.

you'll notice that ??1B@@UAE@XZ is B::~B
and ??_DB@@QAEXXZ is B::'vbase destructor'.

I've forgotten to add the emphasis: ?1B@ does not mean "B base destructor", it really just means "B destructor".
Well, you can tell it is a "B base destructor", but with a slightly different meaning of "base" (not only a base class but also "B basic/simple destructor").

timurrrr edited edge metadata.May 6 2014, 1:45 AM

I suppose a similar patch has landed already?
Can we close this one?

timurrrr resigned from this revision.Mar 26 2015, 9:29 AM
timurrrr removed a reviewer: timurrrr.