summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2009-12-05 22:42:54 +0000
committerAnders Carlsson <andersca@mac.com>2009-12-05 22:42:54 +0000
commit4ed44eb7d96a91c462ad1bb7cd47118dbda78c4d (patch)
treef8e26638df7e3d3d268fff2813829696bda7e36e /clang
parent0ab79e22abf4aa1c64b47bcd9dbc3402f8aad060 (diff)
downloadbcm5719-llvm-4ed44eb7d96a91c462ad1bb7cd47118dbda78c4d.tar.gz
bcm5719-llvm-4ed44eb7d96a91c462ad1bb7cd47118dbda78c4d.zip
Only emit the vtable definition if the class has a key function and we're emitting it, or if the class doesn't have a key function and we are emitting the complete constructor.
llvm-svn: 90681
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/CodeGen/CGVtable.cpp54
1 files changed, 22 insertions, 32 deletions
diff --git a/clang/lib/CodeGen/CGVtable.cpp b/clang/lib/CodeGen/CGVtable.cpp
index 9c78c236313..2ff3e70ea80 100644
--- a/clang/lib/CodeGen/CGVtable.cpp
+++ b/clang/lib/CodeGen/CGVtable.cpp
@@ -1388,27 +1388,11 @@ void CGVtableInfo::GenerateClassData(const CXXRecordDecl *RD) {
}
llvm::Constant *CGVtableInfo::getVtable(const CXXRecordDecl *RD) {
- llvm::Constant *&vtbl = Vtables[RD];
- if (vtbl)
- return vtbl;
- vtbl = CGM.GenerateVtable(RD, RD);
+ llvm::Constant *&Vtable = Vtables[RD];
+ if (!Vtable)
+ Vtable = CGM.GenerateVtable(RD, RD);
- bool CreateDefinition = true;
-
- const ASTRecordLayout &Layout = CGM.getContext().getASTRecordLayout(RD);
- if (const CXXMethodDecl *KeyFunction = Layout.getKeyFunction()) {
- if (!KeyFunction->getBody()) {
- // If there is a KeyFunction, and it isn't defined, just build a
- // reference to the vtable.
- CreateDefinition = false;
- }
- }
-
- if (CreateDefinition) {
- CGM.GenerateRTTI(RD);
- CGM.GenerateVTT(RD);
- }
- return vtbl;
+ return Vtable;
}
llvm::Constant *CGVtableInfo::getCtorVtable(const CXXRecordDecl *LayoutClass,
@@ -1421,25 +1405,31 @@ void CGVtableInfo::MaybeEmitVtable(GlobalDecl GD) {
const CXXMethodDecl *MD = cast<CXXMethodDecl>(GD.getDecl());
const CXXRecordDecl *RD = MD->getParent();
+ // If the class doesn't have a vtable we don't need to emit one.
+ if (!RD->isDynamicClass())
+ return;
+
const ASTRecordLayout &Layout = CGM.getContext().getASTRecordLayout(RD);
// Get the key function.
const CXXMethodDecl *KeyFunction = Layout.getKeyFunction();
- if (!KeyFunction) {
- // If there's no key function, we don't want to emit the vtable here.
- return;
+ if (KeyFunction) {
+ // We don't have the right key function.
+ if (KeyFunction->getCanonicalDecl() != MD->getCanonicalDecl())
+ return;
+
+ // If the key function is a destructor, we only want to emit the vtable
+ // once, so do it for the complete destructor.
+ if (isa<CXXDestructorDecl>(MD) && GD.getDtorType() != Dtor_Complete)
+ return;
+ } else {
+ // If there is no key function, we only want to emit the vtable if we are
+ // emitting a constructor.
+ if (!isa<CXXConstructorDecl>(MD) || GD.getCtorType() != Ctor_Complete)
+ return;
}
- // Check if we have the key function.
- if (KeyFunction->getCanonicalDecl() != MD->getCanonicalDecl())
- return;
-
- // If the key function is a destructor, we only want to emit the vtable once,
- // so do it for the complete destructor.
- if (isa<CXXDestructorDecl>(MD) && GD.getDtorType() != Dtor_Complete)
- return;
-
// Emit the data.
GenerateClassData(RD);
}
OpenPOWER on IntegriCloud