[cfe-commits] r131368 - in /cfe/trunk: include/clang/AST/Decl.h lib/AST/Decl.cpp lib/CodeGen/CGCXX.cpp lib/CodeGen/CGClass.cpp test/CodeGenCXX/mangle-subst-std.cpp test/CodeGenCXX/skip-vtable-pointer-initialization.cpp
Sean Hunt
scshunt at csclub.uwaterloo.ca
Sat May 14 17:35:57 PDT 2011
On 11-05-14 04:26 PM, Anders Carlsson wrote:
> Author: andersca
> Date: Sat May 14 18:26:09 2011
> New Revision: 131368
>
> URL: http://llvm.org/viewvc/llvm-project?rev=131368&view=rev
> Log:
> When emitting the destructor for a class with a vtable, if we can determine
> that the destructor body is trivial and that all member variables also have either
> trivial destructors or trivial destructor bodies, we don't need to initialize the
> vtable pointers since no virtual member functions will be called on the destructor.
>
> Fixes PR9181.
This breaks the following code:
#include <cstdio>
struct DestroyedBase;
struct Base {
DestroyedBase *D;
Base(DestroyedBase *D) : D(D) { }
~Base();
};
struct Derived : Base{
Derived(DestroyedBase *D) : Base(D) { }
~Derived() { }
};
struct DestroyedBase {
Derived D;
virtual void Virtual() {
printf("DestroyedBase::Virtual\n");
}
~DestroyedBase() { }
DestroyedBase() : D(this) { }
};
struct DestroyedDerived : DestroyedBase {
virtual void Virtual() {
printf("DestroyedDerived::Virtual\n");
}
~DestroyedDerived() { }
};
Base::~Base() {
D->Virtual();
}
int main() { DestroyedDerived D; }
You would need to recursively check all members' bases and members for
empty destructor bodies too in order to apply this optimization.
Sean
More information about the cfe-commits
mailing list