diff options
| author | Douglas Gregor <dgregor@apple.com> | 2010-01-05 19:06:31 +0000 |
|---|---|---|
| committer | Douglas Gregor <dgregor@apple.com> | 2010-01-05 19:06:31 +0000 |
| commit | a318efd1f21a21358f45a201f7b6cb2b8b118ec0 (patch) | |
| tree | a4ce378e010ad14d8fd2ec042050df78be33568d /clang/lib/Sema/SemaDeclCXX.cpp | |
| parent | 79ed590c85749e088e80506c831a3da292122c9c (diff) | |
| download | bcm5719-llvm-a318efd1f21a21358f45a201f7b6cb2b8b118ec0.tar.gz bcm5719-llvm-a318efd1f21a21358f45a201f7b6cb2b8b118ec0.zip | |
Improve key-function computation for templates. In particular:
- All classes can have a key function; templates don't change that.
non-template classes when computing the key function.
- We always mark all of the virtual member functions of class
template instantiations.
- The vtable for an instantiation of a class template has weak
linkage.
We could probably use available_externally linkage for vtables of
classes instantiated by explicit instantiation declarations (extern
templates), but GCC doesn't do this and I'm not 100% that the ABI
permits it.
llvm-svn: 92753
Diffstat (limited to 'clang/lib/Sema/SemaDeclCXX.cpp')
| -rw-r--r-- | clang/lib/Sema/SemaDeclCXX.cpp | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 204d7764682..ecf95d7eb66 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -5702,19 +5702,31 @@ void Sema::MaybeMarkVirtualMembersReferenced(SourceLocation Loc, ClassesWithUnmarkedVirtualMembers.insert(std::make_pair(RD, Loc)); return; } - - const CXXMethodDecl *KeyFunction = Context.getKeyFunction(RD); - if (!KeyFunction) { - // This record does not have a key function, so we assume that the vtable - // will be emitted when it's used by the constructor. - if (!isa<CXXConstructorDecl>(MD)) + switch (RD->getTemplateSpecializationKind()) { + case TSK_Undeclared: + case TSK_ExplicitSpecialization: { + const CXXMethodDecl *KeyFunction = Context.getKeyFunction(RD); + + if (!KeyFunction) { + // This record does not have a key function, so we assume that the vtable + // will be emitted when it's used by the constructor. + if (!isa<CXXConstructorDecl>(MD)) + return; + } else if (KeyFunction->getCanonicalDecl() != MD->getCanonicalDecl()) { + // We don't have the right key function. return; - } else if (KeyFunction->getCanonicalDecl() != MD->getCanonicalDecl()) { - // We don't have the right key function. - return; + } + break; } - + + case TSK_ImplicitInstantiation: + case TSK_ExplicitInstantiationDeclaration: + case TSK_ExplicitInstantiationDefinition: + // Always mark the virtual members of an instantiated template. + break; + } + // Mark the members as referenced. MarkVirtualMembersReferenced(Loc, RD); ClassesWithUnmarkedVirtualMembers.erase(RD); |

